Skip to content

Commit

Permalink
Deprecate non nullable project getter
Browse files Browse the repository at this point in the history
  • Loading branch information
seadowg committed Dec 5, 2024
1 parent 4c0bce3 commit 23b2111
Show file tree
Hide file tree
Showing 47 changed files with 139 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ open class FormEntryActivityTestRule :
val form = DaggerUtils.getComponent(application).formsRepositoryProvider().create()
.getOneByPath(formPath)
val projectId = DaggerUtils.getComponent(application).currentProjectProvider()
.getCurrentProject().uuid
.requireCurrentProject().uuid

return FormFillingIntentFactory.newInstanceIntent(
application,
Expand All @@ -106,7 +106,7 @@ open class FormEntryActivityTestRule :
val instance = DaggerUtils.getComponent(application).instancesRepositoryProvider().create()
.getAllByFormId(form!!.formId).first()
val projectId = DaggerUtils.getComponent(application).currentProjectProvider()
.getCurrentProject().uuid
.requireCurrentProject().uuid

return FormFillingIntentFactory.editInstanceIntent(
application,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class DeleteFormsActivity : LocalizedActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
DaggerUtils.getComponent(this).inject(this)

val projectId = projectsDataService.getCurrentProject().uuid
val projectId = projectsDataService.requireCurrentProject().uuid
val projectDependencyModule = projectDependencyModuleFactory.create(projectId)

val viewModelFactory = ViewModelFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ private void startFormsDownload(@NonNull ArrayList<ServerFormDetails> filesToDow
// show dialog box
DialogFragmentUtils.showIfNotShowing(RefreshFormListDialogFragment.class, getSupportFragmentManager());

downloadFormsTask = new DownloadFormsTask(projectsDataService.getCurrentProject().getUuid(), formsDataService);
downloadFormsTask = new DownloadFormsTask(projectsDataService.requireCurrentProject().getUuid(), formsDataService);
downloadFormsTask.setDownloaderListener(this);

if (viewModel.getUrl() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class FormEntryViewModelFactory(
modelClass: Class<T>,
handle: SavedStateHandle
): T {
val projectId = projectsDataService.getCurrentProject().uuid
val projectId = projectsDataService.requireCurrentProject().uuid

return when (modelClass) {
FormEntryViewModel::class.java -> FormEntryViewModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2102,7 +2102,7 @@ private void finishAndReturnInstance() {
String path = getAbsoluteInstancePath();
if (path != null) {
if (formSaveViewModel.getInstance() != null) {
uri = InstancesContract.getUri(projectsDataService.getCurrentProject().getUuid(), formSaveViewModel.getInstance().getDbId());
uri = InstancesContract.getUri(projectsDataService.requireCurrentProject().getUuid(), formSaveViewModel.getInstance().getDbId());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ class FormMapActivity : LocalizedActivity() {
) { _: String?, result: Bundle ->
if (result.containsKey(SelectionMapFragment.RESULT_SELECTED_ITEM)) {
val instanceId = result.getLong(SelectionMapFragment.RESULT_SELECTED_ITEM)
startActivity(FormFillingIntentFactory.editInstanceIntent(this, projectsDataService.getCurrentProject().uuid, instanceId))
startActivity(FormFillingIntentFactory.editInstanceIntent(this, projectsDataService.requireCurrentProject().uuid, instanceId))
} else if (result.containsKey(SelectionMapFragment.RESULT_CREATE_NEW_ITEM)) {
startActivity(FormFillingIntentFactory.newInstanceIntent(this, FormsContract.getUri(projectsDataService.getCurrentProject().uuid, formId)))
startActivity(FormFillingIntentFactory.newInstanceIntent(this, FormsContract.getUri(projectsDataService.requireCurrentProject().uuid, formId)))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void onCreate(Bundle savedInstanceState) {
init();

BulkFinalizationViewModel bulkFinalizationViewModel = new BulkFinalizationViewModel(
projectsDataService.getCurrentProject().getUuid(),
projectsDataService.requireCurrentProject().getUuid(),
scheduler,
instancesDataService,
settingsProvider
Expand Down Expand Up @@ -198,7 +198,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
if (view.isEnabled()) {
Cursor c = (Cursor) listView.getAdapter().getItem(position);
long instanceId = c.getLong(c.getColumnIndex(DatabaseInstanceColumns._ID));
Uri instanceUri = InstancesContract.getUri(projectsDataService.getCurrentProject().getUuid(), instanceId);
Uri instanceUri = InstancesContract.getUri(projectsDataService.requireCurrentProject().getUuid(), instanceId);

String action = getIntent().getAction();
if (Intent.ACTION_PICK.equals(action)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public EntitiesDependencyComponent getEntitiesDependencyComponent() {
@NonNull
@Override
public EntitiesRepository providesEntitiesRepository() {
String projectId = applicationComponent.currentProjectProvider().getCurrentProject().getUuid();
String projectId = applicationComponent.currentProjectProvider().requireCurrentProject().getUuid();
return applicationComponent.entitiesRepositoryProvider().create(projectId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class JavaRosaInitializer(
XFormUtils.setXFormParserFactory(dynamicPreloadXFormParserFactory)

val localEntitiesExternalInstanceParserFactory = LocalEntitiesExternalInstanceParserFactory(
{ entitiesRepositoryProvider.create(projectsDataService.getCurrentProject().uuid) },
{ entitiesRepositoryProvider.create(projectsDataService.requireCurrentProject().uuid) },
{ settingsProvider.getUnprotectedSettings().getBoolean(ProjectKeys.KEY_LOCAL_ENTITIES) }
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class AppConfigurationGenerator(
}

private fun getProjectDetailsAsJson(): JSONObject {
val currentProject = projectsDataService.getCurrentProject()
val currentProject = projectsDataService.requireCurrentProject()

return JSONObject().apply {
put(AppConfigurationKeys.PROJECT_NAME, currentProject.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ class QRCodeScannerFragment : BarCodeScannerFragment() {

@Throws(IOException::class, DataFormatException::class)
override fun handleScanningResult(result: BarcodeResult) {
val oldProjectName = projectsDataService.getCurrentProject().name
val oldProjectName = projectsDataService.requireCurrentProject().name

val settingsImportingResult = settingsImporter.fromJSON(
CompressionUtils.decompress(result.text),
projectsDataService.getCurrentProject()
projectsDataService.requireCurrentProject()
)

when (settingsImportingResult) {
SettingsImportingResult.SUCCESS -> {
Analytics.log(AnalyticsEvents.RECONFIGURE_PROJECT)

val newProjectName = projectsDataService.getCurrentProject().name
val newProjectName = projectsDataService.requireCurrentProject().name
if (newProjectName != oldProjectName) {
File(storagePathProvider.getProjectRootDirPath() + File.separator + oldProjectName).delete()
File(storagePathProvider.getProjectRootDirPath() + File.separator + newProjectName).createNewFile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class QRCodeTabsActivity : LocalizedActivity() {
this,
settingsImporter,
qrCodeDecoder,
projectsDataService.getCurrentProject()
projectsDataService.requireCurrentProject()
)

val menuProvider = QRCodeMenuProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public CursorLoader createCompletedUndeletedInstancesCursorLoader(CharSequence c
}

private CursorLoader getInstancesCursorLoader(String selection, String[] selectionArgs, String sortOrder) {
Uri uri = InstancesContract.getUri(projectsDataService.getCurrentProject().getUuid());
Uri uri = InstancesContract.getUri(projectsDataService.requireCurrentProject().getUuid());

return new CursorLoader(
Collect.getInstance(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class FormUriActivity : LocalizedActivity() {
val uri = intent.data!!
val uriMimeType = contentResolver.getType(uri)!!
if (uriMimeType == FormsContract.CONTENT_ITEM_TYPE) {
startForm(FormsContract.getUri(projectsDataService.getCurrentProject().uuid, savepoint.formDbId))
startForm(FormsContract.getUri(projectsDataService.requireCurrentProject().uuid, savepoint.formDbId))
} else {
startForm(intent.data!!)
}
Expand Down Expand Up @@ -224,7 +224,7 @@ private class FormUriViewModel(
val uriProjectId = uri?.getQueryParameter("projectId")
val projectId = uriProjectId ?: firstProject.uuid

return if (projectId != projectsDataService.getCurrentProject().uuid) {
return if (projectId != projectsDataService.requireCurrentProject().uuid) {
resources.getString(string.wrong_project_selected_for_form)
} else {
null
Expand Down Expand Up @@ -321,7 +321,7 @@ private class FormUriViewModel(

private fun assertDoesNotUseEntitiesOrFormsUpdateNotInProgress(): String? {
val uriMimeType = contentResolver.getType(uri!!)
val projectId = projectsDataService.getCurrentProject().uuid
val projectId = projectsDataService.requireCurrentProject().uuid

if (intent.extras?.getString(ApplicationConstants.BundleKeys.FORM_MODE) == ApplicationConstants.FormModes.VIEW_SENT) {
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void onComplete(SaveToDiskResult saveToDiskResult) {
handleTaskResult(saveToDiskResult, saveRequest);
clearMediaFiles();
}
}, new ArrayList<>(originalFiles.values()), projectsDataService.getCurrentProject().getUuid(), entitiesRepository, instancesRepository).execute();
}, new ArrayList<>(originalFiles.values()), projectsDataService.requireCurrentProject().getUuid(), entitiesRepository, instancesRepository).execute();
}

private void handleTaskResult(SaveToDiskResult taskResult, SaveRequest saveRequest) {
Expand All @@ -273,7 +273,7 @@ private void handleTaskResult(SaveToDiskResult taskResult, SaveRequest saveReque
formController.getAuditEventLogger().logEvent(AuditEvent.AuditEventType.FORM_EXIT, false, clock.get());
formController.getAuditEventLogger().logEvent(AuditEvent.AuditEventType.FORM_FINALIZE, true, clock.get());

instancesDataService.instanceFinalized(projectsDataService.getCurrentProject().getUuid(), form);
instancesDataService.instanceFinalized(projectsDataService.requireCurrentProject().getUuid(), form);
} else {
formController.getAuditEventLogger().logEvent(AuditEvent.AuditEventType.FORM_EXIT, true, clock.get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public QRCodeDecoder providesQRCodeDecoder() {

@Provides
public ServerFormsDetailsFetcher providesServerFormDetailsFetcher(FormsRepositoryProvider formsRepositoryProvider, FormSourceProvider formSourceProvider, ProjectsDataService projectsDataService) {
Project.Saved currentProject = projectsDataService.getCurrentProject();
Project.Saved currentProject = projectsDataService.requireCurrentProject();
FormsRepository formsRepository = formsRepositoryProvider.create(currentProject.getUuid());
return new ServerFormsDetailsFetcher(formsRepository, formSourceProvider.create(currentProject.getUuid()));
}
Expand Down Expand Up @@ -425,7 +425,7 @@ public UUIDGenerator providesUUIDGenerator() {
public InstancesDataService providesInstancesDataService(Application application, ProjectsDataService projectsDataService, InstanceSubmitScheduler instanceSubmitScheduler, ProjectDependencyModuleFactory projectsDependencyProviderFactory, Notifier notifier, PropertyManager propertyManager, OpenRosaHttpInterface httpInterface) {
Function0<Unit> onUpdate = () -> {
application.getContentResolver().notifyChange(
InstancesContract.getUri(projectsDataService.getCurrentProject().getUuid()),
InstancesContract.getUri(projectsDataService.requireCurrentProject().getUuid()),
null
);

Expand Down Expand Up @@ -551,7 +551,7 @@ public ProjectDeleter providesProjectDeleter(ProjectsRepository projectsReposito

@Provides
public ProjectResetter providesProjectResetter(StoragePathProvider storagePathProvider, PropertyManager propertyManager, SettingsProvider settingsProvider, FormsRepositoryProvider formsRepositoryProvider, SavepointsRepositoryProvider savepointsRepositoryProvider, InstancesDataService instancesDataService, ProjectsDataService projectsDataService) {
return new ProjectResetter(storagePathProvider, propertyManager, settingsProvider, formsRepositoryProvider, savepointsRepositoryProvider, instancesDataService, projectsDataService.getCurrentProject().getUuid());
return new ProjectResetter(storagePathProvider, propertyManager, settingsProvider, formsRepositoryProvider, savepointsRepositoryProvider, instancesDataService, projectsDataService.requireCurrentProject().getUuid());
}

@Provides
Expand Down Expand Up @@ -603,7 +603,7 @@ public ImageLoader providesImageLoader() {

@Provides
public BlankFormListViewModel.Factory providesBlankFormListViewModel(FormsRepositoryProvider formsRepositoryProvider, InstancesRepositoryProvider instancesRepositoryProvider, Application application, FormsDataService formsDataService, Scheduler scheduler, SettingsProvider settingsProvider, ChangeLockProvider changeLockProvider, ProjectsDataService projectsDataService) {
return new BlankFormListViewModel.Factory(instancesRepositoryProvider.create(), application, formsDataService, scheduler, settingsProvider.getUnprotectedSettings(), projectsDataService.getCurrentProject().getUuid());
return new BlankFormListViewModel.Factory(instancesRepositoryProvider.create(), application, formsDataService, scheduler, settingsProvider.getUnprotectedSettings(), projectsDataService.requireCurrentProject().getUuid());
}

@Provides
Expand All @@ -614,7 +614,7 @@ public ImageCompressionController providesImageCompressorManager() {

@Provides
public FormLoaderTask.FormEntryControllerFactory formEntryControllerFactory(ProjectsDataService projectsDataService, EntitiesRepositoryProvider entitiesRepositoryProvider, SettingsProvider settingsProvider) {
String projectId = projectsDataService.getCurrentProject().getUuid();
String projectId = projectsDataService.requireCurrentProject().getUuid();
EntitiesRepository entitiesRepository = entitiesRepositoryProvider.create(projectId);
return new CollectFormEntryControllerFactory(entitiesRepository, settingsProvider.getUnprotectedSettings(projectId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private void encryptInstance(Instance instance) throws EncryptionException, IOEx
String instancePath = instance.getInstanceFilePath();
File instanceXml = new File(instancePath);
if (!new File(instanceXml.getParentFile(), "submission.xml.enc").exists()) {
Uri uri = InstancesContract.getUri(projectsDataService.getCurrentProject().getUuid(), instance.getDbId());
Uri uri = InstancesContract.getUri(projectsDataService.requireCurrentProject().getUuid(), instance.getDbId());
InstanceMetadata instanceMetadata = new InstanceMetadata(getInstanceIdFromInstance(instancePath), null, null);
EncryptionUtils.EncryptedFormInformation formInfo = EncryptionUtils.getEncryptedFormInformation(uri, instanceMetadata);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ void init() {
private void updateAutoSendStatus() {
// This shouldn't use WorkManager directly but it's likely this code will be removed when
// we eventually move sending forms to a Foreground Service (rather than a blocking AsyncTask)
String tag = ((FormUpdateAndInstanceSubmitScheduler) instanceSubmitScheduler).getAutoSendTag(projectsDataService.getCurrentProject().getUuid());
String tag = ((FormUpdateAndInstanceSubmitScheduler) instanceSubmitScheduler).getAutoSendTag(projectsDataService.requireCurrentProject().getUuid());
LiveData<List<WorkInfo>> statuses = WorkManager.getInstance().getWorkInfosForUniqueWorkLiveData(tag);
statuses.observe(this, workStatuses -> {
if (workStatuses != null) {
Expand Down Expand Up @@ -379,7 +379,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long row
ToastUtils.showLongToast(this, org.odk.collect.strings.R.string.encrypted_form);
} else {
long instanceId = c.getLong(c.getColumnIndex(DatabaseInstanceColumns._ID));
Intent intent = FormFillingIntentFactory.editInstanceIntent(this, projectsDataService.getCurrentProject().getUuid(), instanceId);
Intent intent = FormFillingIntentFactory.editInstanceIntent(this, projectsDataService.requireCurrentProject().getUuid(), instanceId);
startActivity(intent);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,15 @@ class CurrentProjectViewModel(
projectsDataService.update()
}

val currentProject = projectsDataService.getCurrentProjectFlow().asLiveData()
val currentProject = projectsDataService.getCurrentProject().asLiveData()

fun setCurrentProject(project: Project.Saved) {
Analytics.log(AnalyticsEvents.SWITCH_PROJECT)
projectsDataService.setCurrentProject(project.uuid)
}

fun hasCurrentProject(): Boolean {
return try {
projectsDataService.getCurrentProject()
true
} catch (e: IllegalStateException) {
false
}
return projectsDataService.getCurrentProject().value != null
}

fun refresh() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ class MainMenuViewModel(
fun refreshInstances() {
scheduler.immediate<Any?>({
InstanceDiskSynchronizer(settingsProvider).doInBackground()
instancesDataService.update(projectsDataService.getCurrentProject().uuid)
instancesDataService.update(projectsDataService.requireCurrentProject().uuid)
null
}) { }
}

private val currentProject = projectsDataService.getCurrentProjectFlow().asLiveData()
private val currentProject = projectsDataService.getCurrentProject().asLiveData()
val editableInstancesCount: LiveData<Int> = currentProject.switchMap {
instancesDataService.getEditableCount(it!!.uuid).asLiveData()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class BaseAdminPreferencesFragment extends BasePreferencesFragme
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
projectId = projectsDataService.getCurrentProject().getUuid();
projectId = projectsDataService.requireCurrentProject().getUuid();
adminSettings = settingsProvider.getProtectedSettings(projectId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void onAttach(@NonNull Context context) {
DaggerUtils.getComponent(context).inject(this);
projectPreferencesViewModel = new ViewModelProvider(requireActivity(), factory).get(ProjectPreferencesViewModel.class);

projectId = projectsDataService.getCurrentProject().getUuid();
projectId = projectsDataService.requireCurrentProject().getUuid();
settings = settingsProvider.getUnprotectedSettings(projectId);
}

Expand Down
Loading

0 comments on commit 23b2111

Please sign in to comment.