diff options
author | kseniya <ktomskih@datamonsters.co> | 2017-09-20 18:01:15 +0700 |
---|---|---|
committer | kseniya <ktomskih@datamonsters.co> | 2017-09-20 18:01:15 +0700 |
commit | 9968eaefa2a97ebe495fa51b640e31c78db61ac6 (patch) | |
tree | 4eed12a4ebb2829e336a3da673c7c8462e7ab845 /src/main/scala/xyz/driver/pdsuicommon/utils | |
parent | d5ecec043a3d70dd09bda8a79fcd188f411b47df (diff) | |
parent | d4b18efda238f506103dddbf3b400ae17c797276 (diff) | |
download | rest-query-9968eaefa2a97ebe495fa51b640e31c78db61ac6.tar.gz rest-query-9968eaefa2a97ebe495fa51b640e31c78db61ac6.tar.bz2 rest-query-9968eaefa2a97ebe495fa51b640e31c78db61ac6.zip |
Merge branch 'master' into slick-query-builder
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuicommon/utils')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala | 55 | ||||
-rw-r--r-- | src/main/scala/xyz/driver/pdsuicommon/utils/Utils.scala | 20 |
2 files changed, 75 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala new file mode 100644 index 0000000..c1a2c7c --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala @@ -0,0 +1,55 @@ +package xyz.driver.pdsuicommon.utils + +import java.time.{LocalDate, LocalDateTime} + +import io.swagger.models.properties.Property +import spray.json.JsValue +import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} +import xyz.driver.pdsuidomain.entities._ +import xyz.driver.pdsuidomain.formats.json.sprayformats.arm._ +import xyz.driver.pdsuidomain.formats.json.sprayformats.criterion._ +import xyz.driver.pdsuidomain.formats.json.sprayformats.intervention._ +import xyz.driver.pdsuidomain.formats.json.sprayformats.hypothesis._ +import xyz.driver.pdsuidomain.formats.json.sprayformats.studydesign._ +import xyz.driver.pdsuidomain.formats.json.sprayformats.trial._ +import xyz.driver.pdsuidomain.formats.json.sprayformats.trialhistory._ +import xyz.driver.pdsuidomain.formats.json.sprayformats.trialissue._ +import xyz.driver.core.swagger.CustomSwaggerJsonConverter._ +import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion + +object CustomSwaggerJsonFormats { + + val customCommonProperties = Map[Class[_], Property]( + classOf[LocalDateTime] -> stringProperty(example = Some("2010-12-31'T'18:59:59Z")), + classOf[LocalDate] -> stringProperty(example = Some("2010-12-31")), + classOf[UuidId[_]] -> stringProperty(example = Some("370b0450-35cb-4aab-ba74-0145be75add5")), + classOf[StringId[_]] -> stringProperty(), + classOf[LongId[_]] -> stringProperty() + ) + val customTrialCurationProperties = Map[Class[_], Property]( + classOf[Trial.Status] -> stringProperty(), + classOf[Trial.Condition] -> stringProperty(), + classOf[TrialHistory.Action] -> stringProperty(), + classOf[TrialHistory.State] -> stringProperty() + ) ++ customCommonProperties + + val customTrialCurationObjectsExamples = Map[Class[_], JsValue]( + classOf[Trial] -> trialWriter.write(xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextTrial()), + classOf[Arm] -> armFormat.write(xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextArm()), + classOf[TrialHistory] -> trialHistoryFormat.write( + xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextTrialHistory()), + classOf[TrialIssue] -> trialIssueWriter.write( + xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextTrialIssue()), + classOf[RichCriterion] -> richCriterionFormat.write( + xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextRichCriterion()), + classOf[InterventionWithArms] -> interventionWriter.write( + xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextInterventionWithArms()), + classOf[InterventionType] -> interventionTypeFormat.write( + xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextInterventionType()), + classOf[Hypothesis] -> hypothesisFormat.write( + xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextHypothesis()), + classOf[StudyDesign] -> studyDesignFormat.write( + xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextStudyDesign()) + ) + +} diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/Utils.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/Utils.scala index 02c9e28..63b0572 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/utils/Utils.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/utils/Utils.scala @@ -1,6 +1,7 @@ package xyz.driver.pdsuicommon.utils import java.time.LocalDateTime +import java.util.regex.{Matcher, Pattern} object Utils { @@ -20,4 +21,23 @@ object Utils { fullClassName.substring(fullClassName.lastIndexOf("$") + 1) } } + + def toSnakeCase(str: String): String = + str + .replaceAll("([A-Z]+)([A-Z][a-z])", "$1_$2") + .replaceAll("([a-z\\d])([A-Z])", "$1_$2") + .toLowerCase + + def toCamelCase(str: String): String = { + val sb = new StringBuffer() + def loop(m: Matcher): Unit = if (m.find()) { + m.appendReplacement(sb, m.group(1).toUpperCase()) + loop(m) + } + val m: Matcher = Pattern.compile("_(.)").matcher(str) + loop(m) + m.appendTail(sb) + sb.toString + } + } |