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

[Nullability Annotations to Java Classes] Use Updated and Null Proof TermModel Class (breaking) #19158

Merged
merged 11 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ private boolean addCategory() {
return false;
}

TermModel newCategory = new TermModel();
newCategory.setTaxonomy(TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY);
newCategory.setName(categoryName);
newCategory.setParentRemoteId(parentId);
TermModel newCategory = new TermModel(
TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY,
categoryName,
parentId
);
((SelectCategoriesActivity) getActivity()).categoryAdded(newCategory);

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ class AddCategoryUseCase @Inject constructor(
private val dispatcher: Dispatcher
) {
fun addCategory(categoryName: String, parentCategoryId: Long, siteModel: SiteModel) {
val newCategory = TermModel()
newCategory.taxonomy = TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY
newCategory.name = categoryName
newCategory.parentRemoteId = parentCategoryId
val newCategory = TermModel(
TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY,
categoryName,
parentCategoryId
)
val payload = RemoteTermPayload(newCategory, siteModel)
dispatcher.dispatch(TaxonomyActionBuilder.newPushTermAction(payload))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,24 @@ class EditCategoryUseCase @Inject constructor(
private val dispatcher: Dispatcher
) {
fun editCategory(
existingCategory: TermModel,
categoryId: Long,
existingCategorySlug: String,
categoryName: String,
parentCategoryId: Long,
siteModel: SiteModel
) {
val existingCategory = TermModel()
existingCategory.remoteTermId = categoryId
existingCategory.taxonomy = TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY
existingCategory.name = categoryName
existingCategory.slug = existingCategorySlug
existingCategory.parentRemoteId = parentCategoryId
val payload = RemoteTermPayload(existingCategory, siteModel)
val editedCategory = TermModel(
existingCategory.id,
existingCategory.localSiteId,
categoryId,
TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY,
categoryName,
existingCategory.slug,
existingCategory.description,
parentCategoryId,
existingCategory.postCount
)
val payload = RemoteTermPayload(editedCategory, siteModel)
dispatcher.dispatch(TaxonomyActionBuilder.newPushTermAction(payload))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,14 @@ class PrepublishingCategoriesViewModel @Inject constructor(
}

fun onTermUploadedComplete(event: OnTermUploaded) {
// Sometimes the API will return a success response with a null name which we will
// treat as an error because without a name, there is no category
val isError = event.isError || event.term?.name == null
val message = if (isError) {
val message = if (event.isError) {
R.string.adding_cat_failed
} else {
R.string.adding_cat_success
}
_snackbarEvents.postValue(Event(SnackbarMessageHolder(UiStringRes(message))))

if (!isError) {
if (!event.isError) {
val currentState = uiState.value as UiState
val selectedIds = currentState.categoriesListItemUiState.toMutableList()
.filter { x -> x.checked }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public static SiteSettingsTagDetailFragment newInstance(@Nullable TermModel term
Bundle args = new Bundle();
if (term == null) {
args.putBoolean(ARGS_IS_NEW_TERM, true);
term = new TermModel();
term.setTaxonomy(TaxonomyStore.DEFAULT_TAXONOMY_TAG);
term = new TermModel(TaxonomyStore.DEFAULT_TAXONOMY_TAG);
}
args.putSerializable(ARGS_TERM, term);
fragment.setArguments(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ class CategoryDetailViewModel @Inject constructor(
launch {
_onCategoryPush.postValue(Event(InProgress(R.string.updating_cat)))
editCategoryUseCase.editCategory(
existingCategory!!,
categoryId,
existingCategory!!.slug,
categoryText,
parentCategory.categoryId,
siteModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,16 @@ class PrepublishingCategoriesViewModelTest : BaseUnitTest() {
)

private fun getTermModel(): TermModel {
val termModel = TermModel()
termModel.name = "Cars"
termModel.remoteTermId = 20
termModel.slug = "Cars"
return termModel
return TermModel(
0,
6,
20,
TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY,
"Cars",
"cars",
null,
0,
0
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.wordpress.android.BaseUnitTest
import org.wordpress.android.fluxc.Dispatcher
import org.wordpress.android.fluxc.action.TaxonomyAction.FETCH_CATEGORIES
import org.wordpress.android.fluxc.action.TaxonomyAction
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.fluxc.store.TaxonomyStore.OnTaxonomyChanged
import org.wordpress.android.fluxc.store.TaxonomyStore.TaxonomyError
import org.wordpress.android.fluxc.store.TaxonomyStore.TaxonomyErrorType.GENERIC_ERROR
import org.wordpress.android.fluxc.store.TaxonomyStore.TaxonomyErrorType
import org.wordpress.android.ui.posts.GetCategoriesUseCase
import org.wordpress.android.ui.prefs.categories.list.CategoriesListViewModel
import org.wordpress.android.ui.prefs.categories.list.UiState
Expand Down Expand Up @@ -165,15 +165,12 @@ class CategoriesListViewModelTest : BaseUnitTest() {
}

private fun getGenericTaxonomyError(): OnTaxonomyChanged {
val taxonomyChanged = OnTaxonomyChanged(0)
taxonomyChanged.causeOfChange = FETCH_CATEGORIES
taxonomyChanged.error = TaxonomyError(GENERIC_ERROR)
val taxonomyChanged = OnTaxonomyChanged(0, TaxonomyAction.FETCH_CATEGORIES)
taxonomyChanged.error = TaxonomyError(TaxonomyErrorType.GENERIC_ERROR)
return taxonomyChanged
}

private fun getTaxonomyChangedCallback(): OnTaxonomyChanged {
val taxonomyChanged = OnTaxonomyChanged(0)
taxonomyChanged.causeOfChange = FETCH_CATEGORIES
return taxonomyChanged
return OnTaxonomyChanged(0, TaxonomyAction.FETCH_CATEGORIES)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import org.mockito.kotlin.whenever
import org.wordpress.android.BaseUnitTest
import org.wordpress.android.R
import org.wordpress.android.fluxc.Dispatcher
import org.wordpress.android.fluxc.action.TaxonomyAction.REMOVE_TERM
import org.wordpress.android.fluxc.action.TaxonomyAction
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.fluxc.model.TermModel
import org.wordpress.android.fluxc.store.TaxonomyStore
import org.wordpress.android.fluxc.store.TaxonomyStore.OnTaxonomyChanged
import org.wordpress.android.fluxc.store.TaxonomyStore.OnTermUploaded
import org.wordpress.android.fluxc.store.TaxonomyStore.TaxonomyError
import org.wordpress.android.fluxc.store.TaxonomyStore.TaxonomyErrorType.GENERIC_ERROR
import org.wordpress.android.fluxc.store.TaxonomyStore.TaxonomyErrorType
import org.wordpress.android.models.CategoryNode
import org.wordpress.android.ui.mysite.SelectedSiteRepository
import org.wordpress.android.ui.posts.AddCategoryUseCase
Expand Down Expand Up @@ -227,8 +228,11 @@ class CategoryDetailViewModelTest : BaseUnitTest() {

assertThat(InProgress(R.string.updating_cat)).isEqualTo(onCategoryPushStates[0].peekContent())
verify(editCategoryUseCase).editCategory(
14L, "dog",
updatedCategoryName, 1, siteModel
getChildTermModel(),
14L,
updatedCategoryName,
1,
siteModel
)
}

Expand Down Expand Up @@ -326,40 +330,48 @@ class CategoryDetailViewModelTest : BaseUnitTest() {
}

private fun getParentTermModel(): TermModel {
val termModel = TermModel()
termModel.name = "Animals"
termModel.remoteTermId = 1
termModel.slug = "Animals"
return termModel
return TermModel(
0,
6,
1,
TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY,
"Animals",
"animals",
null,
0,
0
)
}

private fun getChildTermModel(): TermModel {
val termModel = TermModel()
termModel.name = "Dog"
termModel.remoteTermId = 14
termModel.parentRemoteId = 1
termModel.slug = "dog"
return termModel
return TermModel(
0,
6,
14,
TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY,
"Dog",
"dog",
null,
1,
0
)
}

private fun getTermUploadSuccess() = OnTermUploaded(TermModel())
private fun getTermUploadSuccess() = OnTermUploaded(TermModel(TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY))

private fun getTermUploadError(): OnTermUploaded {
val event = OnTermUploaded(TermModel())
event.error = TaxonomyError(GENERIC_ERROR)
val event = OnTermUploaded(TermModel(TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY))
event.error = TaxonomyError(TaxonomyErrorType.GENERIC_ERROR)
return event
}

private fun getTaxonomyChangedCallback(): OnTaxonomyChanged {
val taxonomyChanged = OnTaxonomyChanged(0)
taxonomyChanged.causeOfChange = REMOVE_TERM
return taxonomyChanged
return OnTaxonomyChanged(0, TaxonomyAction.REMOVE_TERM)
}

private fun getTaxonomyChangedErrorCallback(): OnTaxonomyChanged {
val taxonomyChanged = OnTaxonomyChanged(0)
taxonomyChanged.causeOfChange = REMOVE_TERM
taxonomyChanged.error = TaxonomyError(GENERIC_ERROR)
val taxonomyChanged = OnTaxonomyChanged(0, TaxonomyAction.REMOVE_TERM)
taxonomyChanged.error = TaxonomyError(TaxonomyErrorType.GENERIC_ERROR)
return taxonomyChanged
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ext {
automatticTracksVersion = '3.3.0'
gutenbergMobileVersion = 'v1.105.0'
wordPressAztecVersion = 'v1.8.0'
wordPressFluxCVersion = '2.48.0'
wordPressFluxCVersion = 'trunk-55122d0f327b24441003653dcfe7d3cd03bc7972'
wordPressLoginVersion = '1.6.0'
wordPressPersistentEditTextVersion = '1.0.2'
wordPressUtilsVersion = '3.10.0'
Expand Down