forked from eclipse-tractusx/bpdm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bridge): Add SyncRecord for tracking syncs
- Loading branch information
1 parent
2f4fcd5
commit 859cb2b
Showing
5 changed files
with
169 additions
and
5 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/entity/SyncRecord.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
******************************************************************************/ | ||
|
||
package com.catenax.bpdm.bridge.dummy.entity | ||
|
||
import jakarta.persistence.* | ||
import org.eclipse.tractusx.bpdm.common.model.BaseEntity | ||
import org.eclipse.tractusx.bpdm.common.model.BaseSyncRecord | ||
import org.eclipse.tractusx.bpdm.common.model.SyncStatus | ||
import java.time.Instant | ||
|
||
@Entity | ||
@Table(name = "sync_records") | ||
class SyncRecord( | ||
@Enumerated(EnumType.STRING) | ||
@Column(name = "type", nullable = false, unique = true) | ||
override var type: SyncType, | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(name = "status", nullable = false) | ||
override var status: SyncStatus, | ||
|
||
@Column(name = "from_time", nullable = false) | ||
override var fromTime: Instant, | ||
|
||
@Column(name = "progress", nullable = false) | ||
override var progress: Float = 0f, | ||
|
||
@Column(name = "count", nullable = false) | ||
override var count: Int = 0, | ||
|
||
@Column(name = "status_details") | ||
override var errorDetails: String? = null, | ||
|
||
@Column(name = "save_state") | ||
override var errorSave: String? = null, | ||
|
||
@Column(name = "started_at") | ||
override var startedAt: Instant? = null, | ||
|
||
@Column(name = "finished_at") | ||
override var finishedAt: Instant? = null | ||
|
||
) : BaseEntity(), BaseSyncRecord<SyncType> |
24 changes: 24 additions & 0 deletions
24
bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/entity/SyncType.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
******************************************************************************/ | ||
|
||
package com.catenax.bpdm.bridge.dummy.entity | ||
|
||
enum class SyncType { | ||
GATE_TO_POOL | ||
} |
29 changes: 29 additions & 0 deletions
29
...ge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/repository/SyncRecordRepository.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
******************************************************************************/ | ||
|
||
package com.catenax.bpdm.bridge.dummy.repository | ||
|
||
import com.catenax.bpdm.bridge.dummy.entity.SyncRecord | ||
import com.catenax.bpdm.bridge.dummy.entity.SyncType | ||
import org.springframework.data.repository.CrudRepository | ||
|
||
interface SyncRecordRepository : CrudRepository<SyncRecord, Long> { | ||
|
||
fun findByType(type: SyncType): SyncRecord? | ||
} |
46 changes: 46 additions & 0 deletions
46
bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/service/SyncRecordService.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
******************************************************************************/ | ||
|
||
package com.catenax.bpdm.bridge.dummy.service | ||
|
||
import com.catenax.bpdm.bridge.dummy.entity.SyncRecord | ||
import com.catenax.bpdm.bridge.dummy.entity.SyncType | ||
import com.catenax.bpdm.bridge.dummy.repository.SyncRecordRepository | ||
import mu.KotlinLogging | ||
import org.eclipse.tractusx.bpdm.common.model.SyncStatus | ||
import org.eclipse.tractusx.bpdm.common.service.BaseSyncRecordService | ||
import org.springframework.stereotype.Service | ||
import java.time.Instant | ||
|
||
@Service | ||
class SyncRecordService( | ||
private val syncRecordRepository: SyncRecordRepository | ||
) : BaseSyncRecordService<SyncType, SyncRecord>() { | ||
|
||
override val logger = KotlinLogging.logger { } | ||
|
||
override fun newSyncRecord(type: SyncType, syncStartTime: Instant) = | ||
SyncRecord(type, SyncStatus.NOT_SYNCED, syncStartTime) | ||
|
||
override fun save(record: SyncRecord) = | ||
syncRecordRepository.save(record) | ||
|
||
override fun findByType(type: SyncType) = | ||
syncRecordRepository.findByType(type) | ||
} |
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