Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Created clockoffset endpoint and persisted per tenant.
- Loading branch information
1 parent
eefbf8e
commit a3c200e9b14cc47df34881b87b6805aeb5e34f21
Showing
15 changed files
with
680 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright 2017 Kuelap, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.mifos.rhythm.api.v1.domain; | ||
|
||
import org.hibernate.validator.constraints.Range; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* @author Myrle Krantz | ||
*/ | ||
@SuppressWarnings({"WeakerAccess", "unused"}) | ||
public class ClockOffset { | ||
@Range(min = 0, max = 23) | ||
private Integer hours; | ||
|
||
@Range(min = 0, max = 59) | ||
private Integer minutes; | ||
|
||
@Range(min = 0, max = 59) | ||
private Integer seconds; | ||
|
||
public ClockOffset() { | ||
this.hours = 0; | ||
this.minutes = 0; | ||
this.seconds = 0; | ||
} | ||
|
||
public ClockOffset(Integer hours, Integer minutes) { | ||
this.hours = hours; | ||
this.minutes = minutes; | ||
this.seconds = 0; | ||
} | ||
|
||
public ClockOffset(Integer hours, Integer minutes, Integer seconds) { | ||
this.hours = hours; | ||
this.minutes = minutes; | ||
this.seconds = seconds; | ||
} | ||
|
||
public Integer getHours() { | ||
return hours; | ||
} | ||
|
||
public void setHours(Integer hours) { | ||
this.hours = hours; | ||
} | ||
|
||
public Integer getMinutes() { | ||
return minutes; | ||
} | ||
|
||
public void setMinutes(Integer minutes) { | ||
this.minutes = minutes; | ||
} | ||
|
||
public Integer getSeconds() { | ||
return seconds; | ||
} | ||
|
||
public void setSeconds(Integer seconds) { | ||
this.seconds = seconds; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ClockOffset that = (ClockOffset) o; | ||
return Objects.equals(hours, that.hours) && | ||
Objects.equals(minutes, that.minutes) && | ||
Objects.equals(seconds, that.seconds); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(hours, minutes, seconds); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ClockOffset{" + | ||
"hours=" + hours + | ||
", minutes=" + minutes + | ||
", seconds=" + seconds + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2017 Kuelap, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.mifos.rhythm.api.v1.domain; | ||
|
||
import io.mifos.core.test.domain.ValidationTest; | ||
import io.mifos.core.test.domain.ValidationTestCase; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
|
||
/** | ||
* @author Myrle Krantz | ||
*/ | ||
public class ClockOffsetTest extends ValidationTest<ClockOffset> { | ||
public ClockOffsetTest(final ValidationTestCase<ClockOffset> testCase) { | ||
super(testCase); | ||
} | ||
|
||
@Override | ||
protected ClockOffset createValidTestSubject() { | ||
return new ClockOffset(); | ||
} | ||
|
||
@Parameterized.Parameters | ||
public static Collection testCases() { | ||
final Collection<ValidationTestCase> ret = new ArrayList<>(); | ||
ret.add(new ValidationTestCase<ClockOffset>("basicCase") | ||
.adjustment(x -> {}) | ||
.valid(true)); | ||
ret.add(new ValidationTestCase<ClockOffset>("everythingMidRange") | ||
.adjustment(x -> {x.setHours(12); x.setMinutes(30); x.setSeconds(30);}) | ||
.valid(true)); | ||
ret.add(new ValidationTestCase<ClockOffset>("negativeHours") | ||
.adjustment(x -> x.setHours(-1)) | ||
.valid(false)); | ||
ret.add(new ValidationTestCase<ClockOffset>("outOfDayHours") | ||
.adjustment(x -> x.setHours(24)) | ||
.valid(false)); | ||
ret.add(new ValidationTestCase<ClockOffset>("negativeMinutes") | ||
.adjustment(x -> x.setMinutes(-1)) | ||
.valid(false)); | ||
ret.add(new ValidationTestCase<ClockOffset>("outOfRangeMinutes") | ||
.adjustment(x -> x.setMinutes(60)) | ||
.valid(false)); | ||
ret.add(new ValidationTestCase<ClockOffset>("negativeSeconds") | ||
.adjustment(x -> x.setMinutes(-1)) | ||
.valid(false)); | ||
ret.add(new ValidationTestCase<ClockOffset>("outOfRangeSeconds") | ||
.adjustment(x -> x.setMinutes(60)) | ||
.valid(false)); | ||
return ret; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2017 Kuelap, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.mifos.rhythm.listener; | ||
|
||
import io.mifos.core.lang.config.TenantHeaderFilter; | ||
import io.mifos.core.test.listener.EventRecorder; | ||
import io.mifos.rhythm.api.v1.domain.ClockOffset; | ||
import io.mifos.rhythm.api.v1.events.EventConstants; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.jms.annotation.JmsListener; | ||
import org.springframework.messaging.handler.annotation.Header; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @author Myrle Krantz | ||
*/ | ||
@SuppressWarnings("unused") | ||
@Component | ||
public class ClockOffsetEventListener { | ||
private final EventRecorder eventRecorder; | ||
|
||
@Autowired | ||
public ClockOffsetEventListener(@SuppressWarnings("SpringJavaAutowiringInspection") final EventRecorder eventRecorder) { | ||
super(); | ||
this.eventRecorder = eventRecorder; | ||
} | ||
|
||
@JmsListener( | ||
subscription = EventConstants.DESTINATION, | ||
destination = EventConstants.DESTINATION, | ||
selector = EventConstants.SELECTOR_PUT_CLOCKOFFSET | ||
) | ||
public void onChangeClockOffset( | ||
@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant, | ||
final String payload) { | ||
this.eventRecorder.event(tenant, EventConstants.PUT_CLOCKOFFSET, payload, ClockOffset.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2017 Kuelap, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.mifos.rhythm.service.internal.command; | ||
|
||
import io.mifos.rhythm.api.v1.domain.ClockOffset; | ||
|
||
/** | ||
* @author Myrle Krantz | ||
*/ | ||
public class ChangeClockOffsetCommand { | ||
private final String tenantIdentifier; | ||
|
||
private final ClockOffset instance; | ||
|
||
public ChangeClockOffsetCommand( | ||
final String tenantIdentifier, | ||
final ClockOffset instance) { | ||
this.tenantIdentifier = tenantIdentifier; | ||
this.instance = instance; | ||
} | ||
|
||
public String getTenantIdentifier() { | ||
return tenantIdentifier; | ||
} | ||
|
||
public ClockOffset getInstance() { | ||
return instance; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ChangeClockOffsetCommand{" + | ||
"tenantIdentifier='" + tenantIdentifier + '\'' + | ||
", instance=" + instance + | ||
'}'; | ||
} | ||
} |
Oops, something went wrong.