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

Testing BA-MBSE Persistence Refactor Merge #259

Merged
merged 66 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
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
2c0daeb
Merge branch 'ba_persistence_refactor' of https://github.com/BA-MBSE/…
HuiJun Feb 7, 2024
f5ef049
Merge commit '4e4e8586b744bc371db774f2b7115647003d2965' into feature/…
Feb 13, 2024
fe50baf
fix NodePersistence.findById interface argument names
Feb 13, 2024
ceb011f
fix FederatedNodeChangeDomain superclass constructor call
Feb 13, 2024
d042a36
change CommitPersistence.elementHistory interface so DefaultCommitSer…
Feb 13, 2024
1190f31
remove redundant groups read from CameoViewService
Feb 13, 2024
8fab816
remove posted _childViews handling from CameoViewService, this was ha…
Feb 13, 2024
5db7179
continue if no permission to change project org on project update
Feb 13, 2024
1d7513f
reduce amount of commits gotten to test for new project in DefaultCom…
Feb 14, 2024
4db7311
add commitId to node get responses in DefaultNodeService and CameoNod…
Feb 14, 2024
d706aa4
removed duplicated convertJsonToMap function in DefaultNodeService, m…
Feb 14, 2024
322eb78
prevent adding change info to commit if element isn't actually being …
Feb 14, 2024
3ae6efb
fix setting initial commit of added element, prefix deleted key with _
Feb 14, 2024
7e83e9c
fix processElementDeleted
Feb 14, 2024
0340a0d
use commitDAO interface in FederatedNodeChangeDomain instead of commi…
Feb 14, 2024
f453d79
clean up unused things in FederatedNodeChangeDomain
Feb 14, 2024
cd4791e
uncomment child views handling so tests run for now
Feb 15, 2024
aaa1324
if searching by commit id doesn't work, try getting by id directly
Feb 15, 2024
9a9bd03
reduce test delay back to 500
Feb 15, 2024
cd7248f
support updating existing ref's json properties, will resurrect if pr…
Feb 21, 2024
0f5e331
fix updating org name
Feb 21, 2024
1974151
prevent project update from updating schema
Feb 21, 2024
6a49df8
fix setting commit id from commitJson id
Feb 21, 2024
9345bb5
sort commits by descending
Feb 21, 2024
7064a3c
check if commitId is latest for gets and pass in null if it is for pe…
Feb 24, 2024
a30da31
remove any _deleted flag in element to be updated
Feb 24, 2024
7831189
set returned elements refId to match requested refId
Feb 24, 2024
4a91807
set refIds for cameo element gets
Feb 24, 2024
064512b
allow update even if previous element not found
Feb 24, 2024
c76802c
handle if element json not found during gets
Feb 24, 2024
13f1ad7
remove addChildViews delay
Feb 24, 2024
a52046c
throw error if project can't hard delete
Feb 24, 2024
c6aecc5
update project permissions after changing orgs if needed
Feb 24, 2024
1af38d9
continue with element delete even if json not found
Feb 24, 2024
814b718
Merge commit 'f7ac4a8af45c3f3347eec2a2b4d0e9a5fe12f144' into fix/pers…
Mar 10, 2024
e8fc607
add more tests for branching behavior
Mar 11, 2024
b58f138
Merge commit '83ec1f6db8a540e1c8bade294c49fa62a62cec25' into fix/pers…
Mar 17, 2024
13318b9
use returned instance from spring data repository save
Mar 19, 2024
e51fa08
fix branch not found behavior when init branch perms
Mar 25, 2024
a55b5ca
remove unused things in FederatedPermissionUpdatesResponseBuilder
Mar 30, 2024
f178665
remove unneeded element delete processing
Mar 31, 2024
7162f86
users list is available to authenticated users
Mar 31, 2024
844e9eb
tweak commit update in case twc module is used
Mar 31, 2024
7858dfb
commit fail cleanup
Mar 31, 2024
26300d3
fix commit delete
Mar 31, 2024
404ef00
in FederatedNodeChangeDomain.primeNodeChangeInfo, add to any existing…
Mar 31, 2024
27f056a
only further process transacted elements but keep other existing info…
Mar 31, 2024
fce5e38
Merge pull request #260 from Open-MBEE/fix/persistence_refactor_fixes
dlamoris Apr 9, 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
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ 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

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