fix: Remove not found error in get snapshot API (#24684)
## Description This PR stops writing 404 error on log when snapshot is not found in the get snapshot API. #### PR fixes following issue(s) Fixes #24786
This commit is contained in:
parent
e5b727f1f9
commit
f02e5f13e1
|
|
@ -36,6 +36,7 @@ public class ApplicationSnapshot extends BaseDomain {
|
|||
* @return Updated at timestamp in ISO format
|
||||
*/
|
||||
public String getUpdatedTime() {
|
||||
if(this.getUpdatedAt() == null) return null;
|
||||
return DateUtils.ISO_FORMATTER.format(this.getUpdatedAt());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,4 @@ public class ApplicationPagesDTO {
|
|||
Application application;
|
||||
|
||||
List<PageNameIdDTO> pages;
|
||||
|
||||
String latestSnapshotTime;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,13 +67,8 @@ public class ApplicationSnapshotServiceCEImpl implements ApplicationSnapshotServ
|
|||
public Mono<ApplicationSnapshot> getWithoutDataByApplicationId(String applicationId, String branchName) {
|
||||
// get application first to check the permission and get child aka branched application ID
|
||||
return applicationService.findBranchedApplicationId(branchName, applicationId, applicationPermission.getEditPermission())
|
||||
.switchIfEmpty(Mono.error(
|
||||
new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.APPLICATION, applicationId))
|
||||
)
|
||||
.flatMap(applicationSnapshotRepository::findWithoutData)
|
||||
.switchIfEmpty(Mono.error(
|
||||
new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.APPLICATION, applicationId))
|
||||
);
|
||||
.defaultIfEmpty(new ApplicationSnapshot());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import com.appsmith.server.constants.FieldName;
|
|||
import com.appsmith.server.domains.Application;
|
||||
import com.appsmith.server.domains.ApplicationMode;
|
||||
import com.appsmith.server.domains.ApplicationPage;
|
||||
import com.appsmith.server.domains.ApplicationSnapshot;
|
||||
import com.appsmith.server.domains.Layout;
|
||||
import com.appsmith.server.domains.NewPage;
|
||||
import com.appsmith.server.dtos.ApplicationPagesDTO;
|
||||
|
|
@ -236,9 +235,6 @@ public class NewPageServiceCEImpl extends BaseService<NewPageRepository, NewPage
|
|||
permission = applicationPermission.getEditPermission();
|
||||
}
|
||||
|
||||
Mono<ApplicationSnapshot> applicationSnapshotMono = applicationSnapshotRepository.findWithoutData(applicationId)
|
||||
.defaultIfEmpty(new ApplicationSnapshot());
|
||||
|
||||
Mono<Application> applicationMono = applicationService.findById(applicationId, permission)
|
||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.ACL_NO_RESOURCE_FOUND, FieldName.APPLICATION, applicationId)))
|
||||
// Throw a 404 error if the application has never been published
|
||||
|
|
@ -370,7 +366,7 @@ public class NewPageServiceCEImpl extends BaseService<NewPageRepository, NewPage
|
|||
return Mono.just(pageNameIdDTOList);
|
||||
});
|
||||
|
||||
return Mono.zip(applicationMono, pagesListMono, applicationSnapshotMono)
|
||||
return Mono.zip(applicationMono, pagesListMono)
|
||||
.map(tuple -> {
|
||||
log.debug("Populating applicationPagesDTO ...");
|
||||
Application application = tuple.getT1();
|
||||
|
|
@ -382,12 +378,6 @@ public class NewPageServiceCEImpl extends BaseService<NewPageRepository, NewPage
|
|||
applicationPagesDTO.setWorkspaceId(application.getWorkspaceId());
|
||||
applicationPagesDTO.setPages(nameIdDTOList);
|
||||
applicationPagesDTO.setApplication(application);
|
||||
|
||||
// set the latest snapshot time if there is a snapshot for this application for edit mode
|
||||
ApplicationSnapshot applicationSnapshot = tuple.getT3();
|
||||
if(!view && StringUtils.hasLength(applicationSnapshot.getId())) {
|
||||
applicationPagesDTO.setLatestSnapshotTime(applicationSnapshot.getUpdatedTime());
|
||||
}
|
||||
return applicationPagesDTO;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -272,4 +272,29 @@ public class ApplicationSnapshotServiceTest {
|
|||
StepVerifier.create(snapshotFlux)
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@WithUserDetails("api_user")
|
||||
@Test
|
||||
public void getWithoutDataByApplicationId_WhenSnanshotNotFound_ReturnsEmptySnapshot() {
|
||||
String uniqueString = UUID.randomUUID().toString();
|
||||
Workspace workspace = new Workspace();
|
||||
workspace.setName("Test workspace " + uniqueString);
|
||||
|
||||
Mono<ApplicationSnapshot> applicationSnapshotMono = workspaceService.create(workspace)
|
||||
.flatMap(createdWorkspace -> {
|
||||
Application testApplication = new Application();
|
||||
testApplication.setName("Test app for snapshot");
|
||||
testApplication.setWorkspaceId(createdWorkspace.getId());
|
||||
return applicationPageService.createApplication(testApplication);
|
||||
})
|
||||
.flatMap(application1 -> {
|
||||
return applicationSnapshotService.getWithoutDataByApplicationId(application1.getId(), null);
|
||||
});
|
||||
|
||||
StepVerifier.create(applicationSnapshotMono)
|
||||
.assertNext(applicationSnapshot -> {
|
||||
assertThat(applicationSnapshot.getId()).isNull();
|
||||
})
|
||||
.verifyComplete();
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,6 @@ import com.appsmith.external.models.Policy;
|
|||
import com.appsmith.server.domains.Application;
|
||||
import com.appsmith.server.domains.ApplicationMode;
|
||||
import com.appsmith.server.domains.ApplicationPage;
|
||||
import com.appsmith.server.domains.ApplicationSnapshot;
|
||||
import com.appsmith.server.domains.PermissionGroup;
|
||||
import com.appsmith.server.domains.Workspace;
|
||||
import com.appsmith.server.dtos.ApplicationPagesDTO;
|
||||
|
|
@ -237,29 +236,4 @@ public class NewPageServiceTest {
|
|||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUserDetails("api_user")
|
||||
public void findApplicationPagesByApplicationIdViewMode_WhenSnapshotExists_SnapshotTimeReturned() {
|
||||
String randomId = UUID.randomUUID().toString();
|
||||
Workspace workspace = new Workspace();
|
||||
workspace.setName("org_" + randomId);
|
||||
Mono<ApplicationPagesDTO> applicationPagesDTOMono = workspaceService.create(workspace)
|
||||
.flatMap(createdWorkspace -> {
|
||||
Application application = new Application();
|
||||
application.setName("app_" + randomId);
|
||||
return applicationPageService.createApplication(application, createdWorkspace.getId());
|
||||
})
|
||||
.flatMap(application -> {
|
||||
ApplicationSnapshot snapshot = new ApplicationSnapshot();
|
||||
snapshot.setApplicationId(application.getId());
|
||||
snapshot.setChunkOrder(1);
|
||||
return applicationSnapshotRepository.save(snapshot).thenReturn(application);
|
||||
})
|
||||
.flatMap(application -> newPageService.findApplicationPagesByApplicationIdViewMode(application.getId(), false, false));
|
||||
|
||||
StepVerifier.create(applicationPagesDTOMono).assertNext(applicationPagesDTO -> {
|
||||
assertThat(applicationPagesDTO.getLatestSnapshotTime()).isNotNull();
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user