-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Mappers and moved logic from controller to mapper class for res…
…ources
- Loading branch information
1 parent
c96c778
commit a94a428
Showing
121 changed files
with
1,847 additions
and
1,139 deletions.
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
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
45 changes: 45 additions & 0 deletions
45
openmetadata-service/src/main/java/org/openmetadata/service/mapper/EntityMapper.java
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,45 @@ | ||
package org.openmetadata.service.mapper; | ||
|
||
import static org.openmetadata.schema.type.Include.NON_DELETED; | ||
import static org.openmetadata.service.jdbi3.EntityRepository.validateOwners; | ||
import static org.openmetadata.service.jdbi3.EntityRepository.validateReviewers; | ||
import static org.openmetadata.service.util.EntityUtil.getEntityReferences; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
import org.openmetadata.common.utils.CommonUtil; | ||
import org.openmetadata.schema.CreateEntity; | ||
import org.openmetadata.schema.EntityInterface; | ||
import org.openmetadata.schema.type.EntityReference; | ||
import org.openmetadata.service.Entity; | ||
|
||
public interface EntityMapper<T extends EntityInterface, C extends CreateEntity> { | ||
T createToEntity(C create, String user); | ||
|
||
default T copy(T entity, CreateEntity request, String updatedBy) { | ||
List<EntityReference> owners = validateOwners(request.getOwners()); | ||
EntityReference domain = validateDomain(request.getDomain()); | ||
validateReviewers(request.getReviewers()); | ||
entity.setId(UUID.randomUUID()); | ||
entity.setName(request.getName()); | ||
entity.setDisplayName(request.getDisplayName()); | ||
entity.setDescription(request.getDescription()); | ||
entity.setOwners(owners); | ||
entity.setDomain(domain); | ||
entity.setTags(request.getTags()); | ||
entity.setDataProducts(getEntityReferences(Entity.DATA_PRODUCT, request.getDataProducts())); | ||
entity.setLifeCycle(request.getLifeCycle()); | ||
entity.setExtension(request.getExtension()); | ||
entity.setUpdatedBy(updatedBy); | ||
entity.setUpdatedAt(System.currentTimeMillis()); | ||
entity.setReviewers(request.getReviewers()); | ||
return entity; | ||
} | ||
|
||
default EntityReference validateDomain(String domainFqn) { | ||
if (CommonUtil.nullOrEmpty(domainFqn)) { | ||
return null; | ||
} | ||
return Entity.getEntityReferenceByName(Entity.DOMAIN, domainFqn, NON_DELETED); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...etadata-service/src/main/java/org/openmetadata/service/mapper/EntityTimeSeriesMapper.java
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,7 @@ | ||
package org.openmetadata.service.mapper; | ||
|
||
import org.openmetadata.schema.EntityTimeSeriesInterface; | ||
|
||
public interface EntityTimeSeriesMapper<T extends EntityTimeSeriesInterface, C> { | ||
T createToEntity(C create, String user); | ||
} |
17 changes: 17 additions & 0 deletions
17
...ce/src/main/java/org/openmetadata/service/resources/analytics/WebAnalyticEventMapper.java
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,17 @@ | ||
package org.openmetadata.service.resources.analytics; | ||
|
||
import org.openmetadata.schema.analytics.WebAnalyticEvent; | ||
import org.openmetadata.schema.api.tests.CreateWebAnalyticEvent; | ||
import org.openmetadata.service.mapper.EntityMapper; | ||
|
||
public class WebAnalyticEventMapper | ||
implements EntityMapper<WebAnalyticEvent, CreateWebAnalyticEvent> { | ||
@Override | ||
public WebAnalyticEvent createToEntity(CreateWebAnalyticEvent create, String user) { | ||
return copy(new WebAnalyticEvent(), create, user) | ||
.withName(create.getName()) | ||
.withDisplayName(create.getDisplayName()) | ||
.withDescription(create.getDescription()) | ||
.withEventType(create.getEventType()); | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
...ta-service/src/main/java/org/openmetadata/service/resources/apis/APICollectionMapper.java
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,20 @@ | ||
package org.openmetadata.service.resources.apis; | ||
|
||
import static org.openmetadata.service.util.EntityUtil.getEntityReference; | ||
import static org.openmetadata.service.util.EntityUtil.getEntityReferences; | ||
|
||
import org.openmetadata.schema.api.data.CreateAPICollection; | ||
import org.openmetadata.schema.entity.data.APICollection; | ||
import org.openmetadata.service.Entity; | ||
import org.openmetadata.service.mapper.EntityMapper; | ||
|
||
public class APICollectionMapper implements EntityMapper<APICollection, CreateAPICollection> { | ||
@Override | ||
public APICollection createToEntity(CreateAPICollection create, String user) { | ||
return copy(new APICollection(), create, user) | ||
.withService(getEntityReference(Entity.API_SERVICE, create.getService())) | ||
.withEndpointURL(create.getEndpointURL()) | ||
.withApiEndpoints(getEntityReferences(Entity.API_ENDPOINT, create.getApiEndpoints())) | ||
.withSourceHash(create.getSourceHash()); | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
...data-service/src/main/java/org/openmetadata/service/resources/apis/APIEndpointMapper.java
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,21 @@ | ||
package org.openmetadata.service.resources.apis; | ||
|
||
import static org.openmetadata.service.util.EntityUtil.getEntityReference; | ||
|
||
import org.openmetadata.schema.api.data.CreateAPIEndpoint; | ||
import org.openmetadata.schema.entity.data.APIEndpoint; | ||
import org.openmetadata.service.Entity; | ||
import org.openmetadata.service.mapper.EntityMapper; | ||
|
||
public class APIEndpointMapper implements EntityMapper<APIEndpoint, CreateAPIEndpoint> { | ||
@Override | ||
public APIEndpoint createToEntity(CreateAPIEndpoint create, String user) { | ||
return copy(new APIEndpoint(), create, user) | ||
.withApiCollection(getEntityReference(Entity.API_COLLCECTION, create.getApiCollection())) | ||
.withRequestMethod(create.getRequestMethod()) | ||
.withEndpointURL(create.getEndpointURL()) | ||
.withRequestSchema(create.getRequestSchema()) | ||
.withResponseSchema(create.getResponseSchema()) | ||
.withSourceHash(create.getSourceHash()); | ||
} | ||
} |
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
Oops, something went wrong.