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

Reconcile OpenMBEE and Boeing #258

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8803c7c
Adding an example implementation for element level permissions - this…
BA-MBSE Feb 24, 2021
6b6e632
Adding elp tests to circleci config
BA-MBSE Feb 24, 2021
cd851b0
Decouples Federated Persistence layer from controller and service lay…
BA-MBSE Mar 17, 2023
9e17c7b
Remove redundant commit save
BA-MBSE Mar 20, 2023
240359a
CodeQL updates
BA-MBSE Mar 20, 2023
d1cd63d
More CodeQL changes
BA-MBSE Mar 20, 2023
1cc6a06
Added timeout to database delete statement
BA-MBSE Mar 22, 2023
9ddd679
Removing overarching transactional annotations
BA-MBSE Mar 27, 2023
bc41d28
Removed transactional annotations from DefaultPermissionService
BA-MBSE Mar 28, 2023
ff3d4fd
Removed @Transactional annotation from modules that are not tasked wi…
BA-MBSE Mar 28, 2023
b6a0ede
Fixes for failing crud tests
BA-MBSE Mar 29, 2023
9808317
Increased request delay for crud tests
BA-MBSE Mar 29, 2023
a9595f6
Working on fixing permissions test failures
BA-MBSE Mar 30, 2023
23848a0
increased delay in permissions test
BA-MBSE Mar 31, 2023
b07f73b
Fixing problem with bean creation for permissions delegates that was …
BA-MBSE Mar 31, 2023
307a8b9
Fixed artifacts behavior
BA-MBSE Apr 4, 2023
8eb0abb
extending artifacts test delay to 1000 ms
BA-MBSE Apr 4, 2023
a95b385
Fixing elastic test failures
BA-MBSE Apr 5, 2023
066a212
Fixing groups test failures
BA-MBSE Apr 5, 2023
87d24ad
Merge branch 'develop' into ba_persistence_refactor
BA-MBSE Apr 5, 2023
1720c02
Merge branch 'reconcile/openmbee_boeing' into element_level_permissio…
HuiJun Feb 7, 2024
3109c33
Update NodeOperation.java
HuiJun Feb 7, 2024
b572fe8
Update DefaultNodeService.java
HuiJun Feb 7, 2024
77ae830
Update DefaultNodeService.java
HuiJun Feb 7, 2024
7e7b090
Update DefaultNodeService.java
HuiJun Feb 7, 2024
3b4b0c2
Update DefaultNodeService.java
HuiJun Feb 7, 2024
6a5ab6b
Update DefaultNodeService.java
HuiJun Feb 7, 2024
bd85c6f
Update DefaultNodeService.java
HuiJun Feb 7, 2024
db0286e
Update DefaultNodeService.java
HuiJun Feb 7, 2024
731f55c
Merge pull request #156 from BA-MBSE/element_level_permissions_os
HuiJun Feb 7, 2024
bb55fda
Merge branch 'ba_persistence_refactor' of https://github.com/BA-MBSE/…
HuiJun Feb 7, 2024
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
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ jobs:
command: |
docker create -v /etc/newman --name mms_test_configs alpine:3.4 /bin/true
docker cp example/. mms_test_configs:/etc/newman
docker run --volumes-from mms_test_configs --network container:mms -t postman/newman run crud.postman_collection.json -e test-env.json --delay-request 500
docker run --volumes-from mms_test_configs --network container:mms -t postman/newman run crud.postman_collection.json -e test-env.json --delay-request 1000
docker run --volumes-from mms_test_configs --network container:mms -t postman/newman run cameo.postman_collection.json -e test-env.json --delay-request 1000
docker run --volumes-from mms_test_configs --network container:mms -t postman/newman run jupyter.postman_collection.json -e test-env.json --delay-request 500
docker run --volumes-from mms_test_configs --network container:mms -t postman/newman run localauth.postman_collection.json -e test-env.json --delay-request 500
docker run --volumes-from mms_test_configs --network container:mms -t postman/newman run permissions.postman_collection.json -e test-env.json --delay-request 500
docker run --volumes-from mms_test_configs --network container:mms -t postman/newman run permissions.postman_collection.json -e test-env.json --delay-request 1000
docker run --volumes-from mms_test_configs --network container:mms -t postman/newman run search.postman_collection.json -e test-env.json --delay-request 1000
docker run --volumes-from mms_test_configs --network container:mms -t postman/newman run artifacts.postman_collection.json -e test-env.json --delay-request 500
docker run --volumes-from mms_test_configs --network container:mms -t postman/newman run artifacts.postman_collection.json -e test-env.json --delay-request 1000
docker run --volumes-from mms_test_configs --network container:mms -t postman/newman run elastic.postman_collection.json -e test-env.json --delay-request 500
docker run --volumes-from mms_test_configs --network container:mms -t postman/newman run groups.postman_collection.json -e test-env.json --delay-request 500

docker run --volumes-from mms_test_configs --network container:mms -t postman/newman run permissions_elp.postman_collection.json -e test-env.json --delay-request 500
- persist_to_workspace:
root: /home/circleci/
paths:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.openmbee.mms.artifacts.crud;

public class ArtifactsContext {
private static ThreadLocal<Boolean> artifactContext = new ThreadLocal<>();

public static void setArtifactContext(Boolean isArtifactContext) {
artifactContext.set(isArtifactContext);
}

public static boolean isArtifactContext() {
return Boolean.TRUE.equals(artifactContext.get());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.openmbee.mms.artifacts.crud;

import org.openmbee.mms.artifacts.json.ArtifactJson;
import org.openmbee.mms.core.services.NodeChangeInfo;
import org.openmbee.mms.crud.domain.NodeUpdateFilter;
import org.openmbee.mms.json.ElementJson;
import org.springframework.stereotype.Component;

@Component
public class ArtifactsPersistenceNodeUpdateFilter implements NodeUpdateFilter {
@Override
public boolean filterUpdate(NodeChangeInfo nodeChangeInfo, ElementJson updated, ElementJson existing) {
if(ArtifactsContext.isArtifactContext()) {
return true;
}
//Ensure artifacts aren't cleared or added by the regular element update process
if(existing.containsKey(ArtifactJson.ARTIFACTS)) {
updated.put(ArtifactJson.ARTIFACTS, existing.get(ArtifactJson.ARTIFACTS));
} else {
updated.remove(ArtifactJson.ARTIFACTS);
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public void acceptHook(Object payload) {
ElementUpdateHook elementUpdateHook = (ElementUpdateHook) payload;
if(elementUpdateHook.getElements() != null) {
//Ignore any artifact changes coming in outside of the Artifacts Controller
elementUpdateHook.getElements().parallelStream().forEach(v -> {
v.remove(ArtifactJson.ARTIFACTS);
});
elementUpdateHook.getElements().parallelStream().forEach(v ->
v.remove(ArtifactJson.ARTIFACTS)
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package org.openmbee.mms.artifacts.service;

import org.openmbee.mms.artifacts.crud.ArtifactsContext;
import org.openmbee.mms.artifacts.storage.ArtifactStorage;
import org.openmbee.mms.artifacts.ArtifactConstants;
import org.openmbee.mms.artifacts.objects.ArtifactResponse;
import org.openmbee.mms.core.dao.ProjectDAO;
import org.openmbee.mms.core.dao.ProjectPersistence;
import org.openmbee.mms.core.exceptions.BadRequestException;
import org.openmbee.mms.core.exceptions.ConflictException;
import org.openmbee.mms.core.exceptions.NotFoundException;
import org.openmbee.mms.core.objects.ElementsRequest;
import org.openmbee.mms.core.objects.ElementsResponse;
import org.openmbee.mms.core.services.NodeService;
import org.openmbee.mms.crud.services.ServiceFactory;
import org.openmbee.mms.data.domains.global.Project;
import org.openmbee.mms.artifacts.json.ArtifactJson;
import org.openmbee.mms.json.ElementJson;
import org.openmbee.mms.json.ProjectJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
Expand All @@ -30,7 +31,7 @@ public class DefaultArtifactService implements ArtifactService {

private ArtifactStorage artifactStorage;
private ServiceFactory serviceFactory;
private ProjectDAO projectRepository;
private ProjectPersistence projectPersistence;

@Autowired
public void setArtifactStorage(ArtifactStorage artifactStorage) {
Expand All @@ -43,16 +44,19 @@ public void setServiceFactory(ServiceFactory serviceFactory) {
}

@Autowired
public void setProjectRepository(ProjectDAO projectRepository) {
this.projectRepository = projectRepository;
public void setProjectPersistence(ProjectPersistence projectPersistence) {
this.projectPersistence = projectPersistence;
}

@Override
public ArtifactResponse get(String projectId, String refId, String id, Map<String, String> params) {
NodeService nodeService = getNodeService(projectId);
ElementJson elementJson = getElement(nodeService, projectId, refId, id, params);

ArtifactJson artifact = getExistingArtifact(ArtifactJson.getArtifacts(elementJson), params, elementJson);
List<ArtifactJson> artifacts = ArtifactJson.getArtifacts(elementJson);
ArtifactJson artifact = new ArtifactJson();
if (artifacts != null) {
artifact = getExistingArtifact(artifacts, params, elementJson);
}
byte[] data = artifactStorage.get(artifact.getLocation(), elementJson, artifact.getMimeType());
ArtifactResponse response = new ArtifactResponse();
response.setData(data);
Expand Down Expand Up @@ -90,7 +94,12 @@ public ElementsResponse createOrUpdate(String projectId, String refId, String id
elementJson = attachOrUpdateArtifact(elementJson, artifactLocation, fileExtension, mimeType, "internal", checksum);
ElementsRequest elementsRequest = new ElementsRequest();
elementsRequest.setElements(Arrays.asList(elementJson));
return nodeService.createOrUpdate(projectId, refId, elementsRequest, params, user);
try {
ArtifactsContext.setArtifactContext(true);
return nodeService.createOrUpdate(projectId, refId, elementsRequest, params, user);
} finally {
ArtifactsContext.setArtifactContext(false);
}
}

@Override
Expand All @@ -99,20 +108,28 @@ public ElementsResponse disassociate(String projectId, String refId, String id,
ElementJson elementJson = getElement(nodeService, projectId, refId, id, params);

List<ArtifactJson> artifacts = ArtifactJson.getArtifacts(elementJson);
if (artifacts == null) {
throw new NotFoundException("Artifacts not found");
}
ArtifactJson artifact = getExistingArtifact(artifacts, params, elementJson);
artifacts.remove(artifact);
ArtifactJson.setArtifacts(elementJson, artifacts);
ElementsRequest elementsRequest = new ElementsRequest();
elementsRequest.setElements(Arrays.asList(elementJson));
return nodeService.createOrUpdate(projectId, refId, elementsRequest, params, user);
try {
ArtifactsContext.setArtifactContext(true);
return nodeService.createOrUpdate(projectId, refId, elementsRequest, params, user);
} finally {
ArtifactsContext.setArtifactContext(false);
}
}

private ElementJson getElement(NodeService nodeService, String projectId, String refId, String id, Map<String, String> params) {

ElementsResponse elementsResponse = nodeService.read(projectId, refId, id, params);
if(elementsResponse.getElements() == null || elementsResponse.getElements().isEmpty()) {
if (elementsResponse.getElements() == null || elementsResponse.getElements().isEmpty()) {
throw new NotFoundException("Element not found");
} else if(elementsResponse.getElements().size() > 1) {
} else if (elementsResponse.getElements().size() > 1) {
throw new ConflictException("Multiple elements found with id " + id);
} else {
return elementsResponse.getElements().get(0);
Expand All @@ -124,10 +141,18 @@ private ElementJson attachOrUpdateArtifact(ElementJson elementJson, String artif
List<ArtifactJson> artifacts = ArtifactJson.getArtifacts(elementJson);
ArtifactJson artifact;
try {
artifact = getExistingArtifact(artifacts, mimeType, null, elementJson);
//nested try/nullcheck OK?
if (artifacts != null) {
artifact = getExistingArtifact(artifacts, mimeType, null, elementJson);
} else {
throw new NotFoundException("Null artifact exception");
}

} catch(NotFoundException ex) {
artifact = new ArtifactJson();
artifacts.add(artifact);
if (artifacts != null) {
artifacts.add(artifact);
}
}

artifact.setLocation(artifactLocation);
Expand All @@ -145,24 +170,24 @@ private ArtifactJson getExistingArtifact(List<ArtifactJson> artifacts, Map<Strin
}

private ArtifactJson getExistingArtifact(List<ArtifactJson> artifacts, String mimeType, String extension, ElementJson element) {
if(mimeType == null && extension == null) {
if (mimeType == null && extension == null) {
throw new BadRequestException("Missing mimetype or extension");
}
//Element representation is unique by mimeType and extension
Optional<ArtifactJson> existing = artifacts.stream().filter(v -> {
return (mimeType != null && mimeType.equals(v.getMimeType())) || (extension != null && extension.equals(v.getExtension()));
}).findFirst();
if(existing.isPresent()) {
Optional<ArtifactJson> existing = artifacts.stream().filter(v ->
(mimeType != null && mimeType.equals(v.getMimeType())) || (extension != null && extension.equals(v.getExtension()))
).findFirst();
if (existing.isPresent()) {
return existing.get();
}
throw new NotFoundException(element);
}

private String getFileExtension(MultipartFile file) {
String originalFilename = file.getOriginalFilename();
if(originalFilename != null) {
if (originalFilename != null) {
int inx = originalFilename.lastIndexOf('.');
if(inx > 0) {
if (inx > 0) {
return originalFilename.substring(inx + 1);
}
}
Expand Down Expand Up @@ -191,8 +216,8 @@ private String getProjectType(String projectId) {
return getProject(projectId).getProjectType();
}

private Project getProject(String projectId) {
Optional<Project> p = projectRepository.findByProjectId(projectId);
private ProjectJson getProject(String projectId) {
Optional<ProjectJson> p = projectPersistence.findById(projectId);
if (p.isPresent()) {
return p.get();
}
Expand Down
13 changes: 9 additions & 4 deletions authenticator/authenticator.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
dependencies {
implementation project(':rdb')
api project(':core')

api commonDependencies.'spring-security-web'

implementation commonDependencies.'servlet-api'
implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.10.5'
implementation commonDependencies.'jjwt-api'

runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.10.5'
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.10.5'
runtimeOnly commonDependencies.'jjwt-impl'
runtimeOnly commonDependencies.'jjwt-jackson'

testImplementation commonDependencies.'spring-boot-starter-test'
}

tasks {
processResources {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ private Date generateExpirationDate() {

private boolean isTokenExpired(String token) {
final Date expirationDate = getExpirationDateFromToken(token);
return expirationDate.before(new Date());
if (expirationDate != null) {
return expirationDate.before(new Date());
}
return true;
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ ext {
'jackson-databind' : "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion",
'jackson-datatype-hibernate5' : "com.fasterxml.jackson.datatype:jackson-datatype-hibernate5:$jacksonVersion",
'jackson-datatype-jsr310' : "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion",
'jjwt-api' : "io.jsonwebtoken:jjwt-api:$jwtTokenVersion",
'jjwt-impl' : "io.jsonwebtoken:jjwt-impl:$jwtTokenVersion",
'jjwt-jackson' : "io.jsonwebtoken:jjwt-jackson:$jwtTokenVersion",
'spring-boot-starter-test' : 'org.springframework.boot:spring-boot-starter-test:2.2.4.RELEASE'
]
}
Expand Down
1 change: 1 addition & 0 deletions cameo/cameo.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
dependencies {
implementation project(':crud')
implementation project(':view')

testImplementation commonDependencies.'spring-boot-starter-test'
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class CameoConstants {
public static final String CLASSIFIERIDS = "classifierIds";
public static final String CLIENTDEPENDENCYIDS = "clientDependencyIds";
public static final String COLLABORATIONUSEIDS = "collaborationUseIds";
public static final String COMMITID = "commitId";
public static final String DATATYPEID = "datatypeId";
public static final String DEFAULTVALUE = "defaultValue";
public static final String DEFININGFEATUREID = "definingFeatureId";
Expand Down Expand Up @@ -46,12 +47,15 @@ public class CameoConstants {
public static final String NAME = "name";
public static final String NAMEEXPRESSION = "nameExpression";
public static final String NAVIGABLEOWNEDENDIDS = "navigableOwnedEndIds";
public static final String NONE = "none";
public static final String OWNEDATTRIBUTEIDS = "ownedAttributeIds";
public static final String OWNEDENDIDS = "ownedEndIds";
public static final String OWNERID = "ownerId";
public static final String PACKAGEIMPORTIDS = "packageImportIds";
public static final String PACKAGEMERGEIDS = "packageMergeIds";
public static final String PARENTID = "_parentId";
public static final String POWERTYPEEXTENTIDS = "powertypeExtentIds";
public static final String PROPERTY = "Property";
public static final String PROPERTYID = "propertyId";
public static final String PROPERTYTYPE = "propertyType";
public static final String PROFILEAPPLICATIONIDS = "profileApplicationIds";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.openmbee.mms.cameo.services;

import org.openmbee.mms.core.config.ContextHolder;
import org.openmbee.mms.core.services.CommitService;
import org.openmbee.mms.crud.services.DefaultCommitService;
import org.openmbee.mms.data.domains.scoped.Commit;
import org.openmbee.mms.json.CommitJson;
import org.springframework.stereotype.Service;

import java.util.List;
Expand All @@ -12,8 +11,7 @@
public class CameoCommitService extends DefaultCommitService implements CommitService {
@Override
public boolean isProjectNew(String projectId) {
ContextHolder.setContext(projectId);
List<Commit> commits = commitRepository.findAll();
List<CommitJson> commits = commitPersistence.findAllByProjectId(projectId);
return commits == null || commits.size() <= 1; // a cameo project gets 1 auto commit, so its still "new"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import java.util.Set;
import org.openmbee.mms.cameo.CameoConstants;
import org.openmbee.mms.cameo.CameoNodeType;
import org.openmbee.mms.core.utils.ElementUtils;
import org.openmbee.mms.json.ElementJson;
import org.springframework.stereotype.Component;

@Component
public class CameoHelper {
public class CameoHelper implements ElementUtils {

@Override
public CameoNodeType getNodeType(ElementJson e) {
if (isDocument(e)) {
return CameoNodeType.DOCUMENT;
Expand Down
Loading
Loading