Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hanmoi-choi/zendesk


https://github.com/hanmoi-choi/zendesk

cats scala

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

        

# Zendesk Search App
This repo is to submit my code exercise to Zendesk.
Zendesk describes that it is fine for me to use Public repo for my exercise.

# Assumption
1. For me this is malformed ISO8601 format, `"2016-05-21T11:10:28 -10:00"` but assumed that it is on purpose.
- There should not be `space` before timezone adjustment, `-10:00`

2. I decided Optional fields myself based on the given data. I assumed that fields having `null` value is optional ones.

- Users
- `alias`: Option[Alias],
- `verified`: Option[Verified],
- `locale`: Option[Locale],
- `timezone`: Option[Timezone],
- `email`: Option[Email],
- `organizationId`: Option[OrganizationId],

- Organizations
- None

- Tickets
- `type`: Option[Type],
- `description`: Option[Description],
- `assigneeId`: Option[AssigneeId],
- `organizationId`: Option[OrganizationId],
- `dueAt`: Option[ZenDateTime],

3. For this statement, `The user should also be able to search for empty values, e.g. where description is empty`.
In the data, description is nullable value so assumed that only nullable value could searchable with `Empty string value`, which is stated at #2.

4. I assumed that my UX does not have to be the same as the provided sample.
- I wanted to display the searchable fields for the object users are selected.
- Screenshot is attached at Appendix

5. Search value is case-sensitive and Search term(field) is case-insensitive.

- `Enter search term` is case-insensitive
- `Enter search value` is case-sensitive

![](./resources/search.png)

# Approach

## Libraries I used
- [Circe](https://circe.github.io/circe/) to parse Json data files; users.json, tickets.json, and organizations.json
- [Cats](https://typelevel.org/cats/) for general FP type classes like Either.
- [Cats-Effect](https://typelevel.org/cats-effect/) for IO Monad
- [Spec2](https://etorreborre.github.io/specs2/) this is just personal preference. I found that this style is better than scala-test but could be opinionated
- [Scala Check](http://www.scalacheck.org/) for Simple Property Check
- [FastParser](http://www.lihaoyi.com/fastparse/#FastParse2.2.2) to parse Console Input, Using Regex makes code quit hard understand

## Functional Programming
In the job description, FP is desired skill so thought that I could do my best with FP.

Except a few codes almost all codes are pure; I did not use mock for testing.

Exceptions are
1. Read JSON data files
2. Creating Database data structure.
3. Main class.

## Diagrams

### Relationships among object to be used for search
![](./resources/Relationships.png)

### Data Structure for Database Class
I have used these two Scala class based on [this scala doc](https://docs.scala-lang.org/overviews/collections-2.13/performance-characteristics.html) for `BigO performance`
- Either mutable or immutable HashMap
- Vector

![](./resources/Database_Internal.jpg)

## Performance
1. Throughput
- Description mentioned that I could assume Memory could store all data so this will not be tested.
- It does not matter how much text data will be flushed into IO.

2. Latency; Result was acceptable, I felt less than 1 sec delay.
- Search time should not BigO(N)
- I have created 3 files under `./data` directory which have 150 times more data than the given data.
- many-users.json
- many-tickets.json
- many-organizations.json
- `JAVA_OPTS="-Xmx2g" scala target/scala-2.13/zendesk.jar data/many-users.json data/many-organizations.json data/many-tickets.json`
- need to increase JVM heapsize; Search Users with `organizationId` and `empty string`.
- `auto/run data/many-users.json data/many-organizations.json data/many-tickets.json`

![](./resources/test-machine.png)

# Development

## Initial execution takes time
This is due to download `sbt` and `libraries` so please be patient.

## Setup Environment
**sometime after running your test from docker the file owner tend to be changed as `root`**

This command will fix the issue

> sudo chown -r $USER:$USER .
>
### Without Docker
1. [Install Open JDK 8u222](https://openjdk.java.net/install/)
2. [Install sbt 1.3.6](https://www.scala-sbt.org/)
2. [Scala 2.13.1](https://www.scala-lang.org/)
4. Execute `Commands` below for either test or execute app

#### Commands

##### Run Test

`sbt clean test`

##### Run App

1. `sbt clean assembly`

2. `scala target/scala-2.13/zendesk.jar `
- when optional params are not provided the default data files are used under `./data` directory
- users.json
- tickets.json
- organizations.json

### With Docker
1. [Install Latest Docker](https://docs.docker.com/v17.12/install/)
2. [Install Docker Compose](https://docs.docker.com/compose/install/)
3. Use docker container, `auto/dev-environment`
4. Execute `Commands** below for either test or execute app

#### Commands

##### Get into Docker Container
`auto/dev-environment`

##### Run Test
`auto/test`

##### Run App
`auto/run `

## Appendix

### Sample Result
![](./resources/SampleResult.png)