Skip to content

Commit

Permalink
Merge more RESTOperations
Browse files Browse the repository at this point in the history
  • Loading branch information
FloBoJa committed Mar 2, 2024
1 parent 2741e20 commit e55ab74
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,23 @@ public static <T extends OperationInterface> Map<OperationInterface, List<Operat
}
if (isRoot) {
for (final OperationInterface rootInterface : groupedDependencies.keySet()) {
final Optional<String> commonInterfaceName = grouplessDependency.getName()
final Optional<String> commonName = grouplessDependency.getName()
.getCommonInterface(rootInterface.getName());
boolean containsOtherDependency = false;

if (!commonInterfaceName.isPresent()) {
if (!commonName.isPresent()) {
continue;
}

final OperationInterface commonInterface = new EntireInterface(rootInterface.getName()
.createInterface(commonInterfaceName.get()));
Name commonInterfaceName = rootInterface.getName()
.createName(commonName.get());
OperationInterface commonInterface;

if (commonInterfaceName instanceof RESTOperationName restName) {
commonInterface = new RESTOperationUnion(restName);
} else {
commonInterface = new EntireInterface(commonInterfaceName);
}

for (final OperationInterface dependency : allDependencies) {
// Check all foreign dependencies
Expand All @@ -68,8 +75,12 @@ public static <T extends OperationInterface> Map<OperationInterface, List<Operat
// De-duplicate interfaces.
final Set<OperationInterface> interfaces = new HashSet<>(
groupedDependencies.remove(rootInterface));
interfaces.add(commonInterface);
interfaces.add(rootInterface);
if (!(commonInterface instanceof RESTOperationUnion)) {
interfaces.add(commonInterface);
}
if (!(rootInterface instanceof RESTOperationUnion)) {
interfaces.add(rootInterface);
}
interfaces.add(grouplessDependency);
groupedDependencies.put(commonInterface, new ArrayList<>(interfaces));
isRoot = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

public class EntireInterface implements OperationInterface {
private final Optional<ITypeBinding> binding;
private final InterfaceName name;
private final Name name;

public EntireInterface(final InterfaceName name) {
public EntireInterface(final Name name) {
this.binding = Optional.empty();
this.name = name;
}

public EntireInterface(final ITypeBinding binding, final InterfaceName name) {
public EntireInterface(final ITypeBinding binding, final Name name) {
this.binding = Optional.of(binding);
this.name = name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public List<String> getInterfaces() {
}

@Override
public InterfaceName createInterface(final String name) {
public InterfaceName createName(final String name) {
return new JavaInterfaceName(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public String getInterface() {
}

@Override
public InterfaceName createInterface(final String name) {
public InterfaceName createName(final String name) {
return new JavaInterfaceName(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Set;

public interface Name {
InterfaceName createInterface(String name);
Name createName(String name);

/**
* @returns interfaces that this name is part of, sorted from specific to general.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public OperationName getName() {
return this.name;
}

@Override
public boolean isPartOf(final OperationInterface other) {
if (other instanceof Operation otherOperation) {
return Objects.equals(this.binding, otherOperation.binding);
} else {
return OperationInterface.super.isPartOf(other);
}
}

@Override
public Map<OperationInterface, Set<Operation>> simplified() {
return Map.of(this, Set.of(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public List<String> getInterfaces() {
}

@Override
public InterfaceName createInterface(final String name) {
public InterfaceName createName(final String name) {
return parse(name).orElseThrow();
}

Expand Down Expand Up @@ -164,6 +164,10 @@ public boolean isPartOf(final String iface) {
}

public static Optional<RESTName> parse(final String iface) {
if (iface.contains("[")) {
// If a HTTP method is present, iface is not a RESTName.
return Optional.empty();
}
final Optional<List<String>> interfacePathOption = parsePath(iface);
if (interfacePathOption.isEmpty()) {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public List<String> getInterfaces() {
}

@Override
public InterfaceName createInterface(final String name) {
return RESTName.parse(name)
public Name createName(final String name) {
return RESTOperationName.parse(name)
.orElseThrow();
}

Expand Down Expand Up @@ -113,21 +113,26 @@ public Optional<String> getCommonInterface(final Name other) {

@Override
public boolean isPartOf(final String iface) {
if (RESTName.parse(iface)
.isPresent()) {
return restName.isPartOf(iface);
}

Optional<RESTOperationName> parsedIface = parse(iface);
if (parsedIface.isEmpty()) {
return false;
}

RESTOperationName restIface = parsedIface.get();

if (!this.restName.isPartOf(restIface.restName.toString())) {
if (!this.restName.equals(restIface.restName)) {
return false;
}

Set<HTTPMethod> normalHttpMethods = new HashSet<>(this.httpMethods);
normalHttpMethods.remove(HTTPMethod.WILDCARD);

if (this.restName.equals(restIface.restName) && !restIface.httpMethods.contains(HTTPMethod.WILDCARD)
if (!restIface.httpMethods.contains(HTTPMethod.WILDCARD)
&& !restIface.httpMethods.containsAll(this.httpMethods)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.palladiosimulator.retriever.extraction.commonalities;

import java.util.Map;
import java.util.Objects;
import java.util.Set;

public class RESTOperationUnion implements OperationInterface {
Expand All @@ -24,4 +25,30 @@ public Map<OperationInterface, Set<Operation>> simplified() {
public String getInterface() {
return name.getInterface();
}

@Override
public String toString() {
return name.toString();
}

@Override
public int hashCode() {
return Objects.hash(name);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
RESTOperationUnion other = (RESTOperationUnion) obj;
return Objects.equals(name, other.name);
}

}

0 comments on commit e55ab74

Please sign in to comment.