Skip to content

Commit

Permalink
zerocracy#559 adding skills to people
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyk committed Jul 10, 2018
1 parent b0969eb commit da10dda
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 7 deletions.
Expand Up @@ -22,11 +22,11 @@ import com.zerocracy.farm.Assume

def exec(Project pmo, XML xml) {
new Assume(pmo, xml).isPmo()
new Assume(pmo, xml).type('Ping daily')
/**
* @todo #492:30min Let's implement this stakeholder. It will take
* a random user from the list, which has the oldest updated attribute,
* go to its GitHub account, fetch all repositories he owns and contributes
* to and fetch the most popular languages from them.
* GitHub provides that information.
* @todo #559:30min Create a method People.oldestSkillsUpdate to retrieve the
* login of the user that needs theirs skills updated and fetch all
* repositories he owns and contributes to and fetch the most popular
* languages from them. GitHub provides that information.
*/
}
}
56 changes: 55 additions & 1 deletion src/main/java/com/zerocracy/pmo/People.java
Expand Up @@ -27,9 +27,11 @@
import com.zerocracy.cash.CashParsingException;
import com.zerocracy.pm.staff.Roles;
import java.io.IOException;
import java.time.Instant;
import java.util.Date;
import java.util.Iterator;
import org.cactoos.iterable.ItemAt;
import org.cactoos.iterable.Joined;
import org.cactoos.iterable.Mapped;
import org.cactoos.scalar.NumberOf;
import org.cactoos.scalar.UncheckedScalar;
Expand Down Expand Up @@ -846,6 +848,58 @@ public Date appliedTime(final String uid) throws IOException {
}
}

/**
* Skills of a person
* @param uid Person's login
* @return Iterable with skills
* @throws IOException If fails
*/
public Iterable<String> skills(final String uid) throws IOException {
try (final Item item = this.item()) {
return new Mapped<>(
xml -> xml.node().getTextContent(),
new Xocument(item.path()).nodes(
String.format(
"/people/person[@id = '%s']/skills/skill",
uid
)
)
);
}
}

/**
* Update the list of user skills.
* @param uid User id
* @param skills List of skills
* @throws IOException If fails
*/
public void skills(final String uid, final Iterable<String> skills)
throws IOException {
this.checkExisting(uid);
try (final Item item = this.item()) {
new Xocument(item.path()).modify(
new Directives().xpath(
String.format(
"/people/person[@id='%s']/skills",
uid
)
)
.remove()
.add("skills").attr("updated", Instant.now())
.append(
new Joined<>(
new Mapped<>(
skill -> new Directives().add("skill")
.set(skill).up(),
skills
)
)
)
);
}
}

/**
* The item.
* @return Item
Expand Down Expand Up @@ -874,7 +928,7 @@ private static Directives start(final String uid) {
.add("jobs").set("0").up()
.add("projects").set("0").up()
.add("speed").set("0.0").up()
.add("skills").attr("updated", new DateAsText().asString()).up()
.add("skills").attr("updated", Instant.now()).up()
.add("links")
.add("link")
.attr("rel", "github")
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/zerocracy/tk/TkTeam.java
Expand Up @@ -46,6 +46,8 @@
* @todo #1121:30min Speed and Agenda is skipped now because it
* causes slow page loading. We have to fix #1121 bug and show
* it on page as before.
* @todo #559:30min Let's display the data from people/skills on the profile
* page of a given user as well as on the team page.
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public final class TkTeam implements Take {
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/com/zerocracy/pmo/PeopleTest.java
Expand Up @@ -24,8 +24,10 @@
import com.zerocracy.farm.fake.FkProject;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.cactoos.iterable.IterableOf;
import org.cactoos.iterable.Mapped;
import org.cactoos.iterable.RangeOf;
import org.cactoos.list.ListOf;
Expand Down Expand Up @@ -549,6 +551,20 @@ public void setsLinks() throws Exception {
);
}

@Test
public void setsSkills() throws IOException {
final People people =
new People(new FkFarm(new FkProject())).bootstrap();
final String uid = "user";
people.invite(uid, "0crat");
final Iterable<String> skills = new IterableOf<>("c", "cobol");
people.skills(uid, skills);
MatcherAssert.assertThat(
new ArrayList<>(new ListOf<>(people.skills(uid))),
Matchers.equalTo(new ArrayList<>(new ListOf<>(skills)))
);
}

private void failsWallet(final String bank, final String wallet)
throws IOException {
final FkFarm farm = new FkFarm(new FkProject());
Expand Down

0 comments on commit da10dda

Please sign in to comment.