mirror of https://github.com/tasks/tasks
Remove TagService
parent
4f2cba7abc
commit
16910c53c9
@ -0,0 +1,51 @@
|
||||
package org.tasks.data;
|
||||
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.with;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.tasks.makers.TagDataMaker.NAME;
|
||||
import static org.tasks.makers.TagDataMaker.newTagData;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import javax.inject.Inject;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.tasks.injection.InjectingTestCase;
|
||||
import org.tasks.injection.TestComponent;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class TagDataDaoTest extends InjectingTestCase {
|
||||
|
||||
@Inject TagDataDao tagDataDao;
|
||||
|
||||
@Test
|
||||
public void tagDataOrderedByNameIgnoresNullNames() {
|
||||
tagDataDao.createNew(newTagData(with(NAME, (String) null)));
|
||||
|
||||
assertTrue(tagDataDao.tagDataOrderedByName().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tagDataOrderedByNameIgnoresEmptyNames() {
|
||||
tagDataDao.createNew(newTagData(with(NAME, "")));
|
||||
|
||||
assertTrue(tagDataDao.tagDataOrderedByName().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTagWithCaseForMissingTag() {
|
||||
assertEquals("derp", tagDataDao.getTagWithCase("derp"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTagWithCaseFixesCase() {
|
||||
tagDataDao.createNew(newTagData(with(NAME, "Derp")));
|
||||
|
||||
assertEquals("Derp", tagDataDao.getTagWithCase("derp"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void inject(TestComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package org.tasks.makers;
|
||||
|
||||
import static com.natpryce.makeiteasy.Property.newProperty;
|
||||
import static org.tasks.makers.Maker.make;
|
||||
|
||||
import com.natpryce.makeiteasy.Instantiator;
|
||||
import com.natpryce.makeiteasy.Property;
|
||||
import com.natpryce.makeiteasy.PropertyValue;
|
||||
import org.tasks.data.TagData;
|
||||
|
||||
public class TagDataMaker {
|
||||
|
||||
public static final Property<TagData, String> NAME = newProperty();
|
||||
|
||||
private static final Instantiator<TagData> instantiator = lookup -> {
|
||||
TagData tagData = new TagData();
|
||||
tagData.setName(lookup.valueOf(NAME, "tag"));
|
||||
return tagData;
|
||||
};
|
||||
|
||||
@SafeVarargs
|
||||
public static TagData newTagData(PropertyValue<? super TagData, ?>... properties) {
|
||||
return make(instantiator, properties);
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
|
||||
package com.todoroo.astrid.tags;
|
||||
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
import static com.google.common.collect.Lists.transform;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import org.tasks.data.TagDao;
|
||||
import org.tasks.data.TagData;
|
||||
import org.tasks.data.TagDataDao;
|
||||
import org.tasks.injection.ApplicationScope;
|
||||
|
||||
/**
|
||||
* Provides operations for working with tags
|
||||
*
|
||||
* @author Tim Su <tim@todoroo.com>
|
||||
*/
|
||||
@ApplicationScope
|
||||
public final class TagService {
|
||||
|
||||
private final TagDataDao tagDataDao;
|
||||
private final TagDao tagDao;
|
||||
|
||||
@Inject
|
||||
public TagService(TagDataDao tagDataDao, TagDao tagDao) {
|
||||
this.tagDataDao = tagDataDao;
|
||||
this.tagDao = tagDao;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all tags ordered by given clause
|
||||
*
|
||||
* @return empty array if no tags, otherwise array
|
||||
*/
|
||||
public TagData[] getGroupedTags() {
|
||||
List<TagData> tags = tagDataDao.tagDataOrderedByName();
|
||||
return tags.toArray(new TagData[tags.size()]);
|
||||
}
|
||||
|
||||
public TagData tagFromUUID(String uuid) {
|
||||
return tagDataDao.getByUuid(uuid);
|
||||
}
|
||||
|
||||
public List<TagData> getTagDataForTask(String uuid) {
|
||||
List<String> uuids = tagDao.getTagUids(uuid);
|
||||
return newArrayList(transform(uuids, this::tagFromUUID));
|
||||
}
|
||||
|
||||
public ArrayList<TagData> getTagDataForTask(long taskId) {
|
||||
List<String> uuids = tagDao.getTagUids(taskId);
|
||||
return newArrayList(transform(uuids, this::tagFromUUID));
|
||||
}
|
||||
|
||||
/** Return all tags (including metadata tags and TagData tags) in an array list */
|
||||
public List<TagData> getTagList() {
|
||||
final List<TagData> tagList = new ArrayList<>();
|
||||
for (TagData tagData : tagDataDao.tagDataOrderedByName()) {
|
||||
if (!TextUtils.isEmpty(tagData.getName())) {
|
||||
tagList.add(tagData);
|
||||
}
|
||||
}
|
||||
return tagList;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a tag already exists in the database that case insensitively matches the given tag, return
|
||||
* that. Otherwise, return the argument
|
||||
*/
|
||||
public String getTagWithCase(String tag) {
|
||||
TagData tagData = tagDataDao.getTagByName(tag);
|
||||
if (tagData != null) {
|
||||
return tagData.getName();
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void rename(String uuid, String newName) {
|
||||
tagDataDao.rename(uuid, newName);
|
||||
tagDao.rename(uuid, newName);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue