-
Notifications
You must be signed in to change notification settings - Fork 14
US97526: Change attribute connector persistence to JSON #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,6 @@ | |
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import com.ge.predix.acs.attribute.connector.management.dao.AttributeConnectorEntity; | ||
| import com.ge.predix.acs.attribute.connector.management.dao.ConnectorConverter; | ||
| import com.ge.predix.acs.rest.AttributeAdapterConnection; | ||
| import com.ge.predix.acs.rest.AttributeConnector; | ||
| import com.ge.predix.acs.zone.management.dao.ZoneEntity; | ||
|
|
@@ -20,19 +18,17 @@ public class AttributeConnectorServiceImpl implements AttributeConnectorService | |
| @Autowired | ||
| private ZoneResolver zoneResolver; | ||
|
|
||
| private final ConnectorConverter connectorConverter = new ConnectorConverter(); | ||
|
|
||
| @Override | ||
| public boolean upsertResourceConnector(final AttributeConnector connector) { | ||
| ZoneEntity zoneEntity = this.zoneResolver.getZoneEntityOrFail(); | ||
| validateConnectorConfigOrFail(connector); | ||
|
|
||
| AttributeConnectorEntity connectorEntity = zoneEntity.getResourceAttributeConnector(); | ||
| boolean isCreated = null == connectorEntity; | ||
|
|
||
| connectorEntity = connectorConverter.toConnectorEntity(connector); | ||
| zoneEntity.setResourceAttributeConnector(connectorEntity); | ||
| boolean isCreated = false; | ||
| try { | ||
| AttributeConnector existingConnector = zoneEntity.getResourceAttributeConnector(); | ||
| isCreated = (null == existingConnector); | ||
|
|
||
| zoneEntity.setResourceAttributeConnector(connector); | ||
| this.zoneRepository.save(zoneEntity); | ||
| } catch (Exception e) { | ||
| String message = String.format( | ||
|
|
@@ -46,18 +42,25 @@ public boolean upsertResourceConnector(final AttributeConnector connector) { | |
| @Override | ||
| public AttributeConnector retrieveResourceConnector() { | ||
| ZoneEntity zoneEntity = this.zoneResolver.getZoneEntityOrFail(); | ||
| return this.connectorConverter.toConnector(zoneEntity.getResourceAttributeConnector()); | ||
| try { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we add throws clause to this function
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guys,
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding is that is the current format of the Json. The Object Mapper deserializes the object into those fields.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Talked with Frank the last comment is not an issue |
||
| return zoneEntity.getResourceAttributeConnector(); | ||
| } catch (Exception e) { | ||
| String message = String.format( | ||
| "Unable to retrieve connector configuration for resource attributes for zone '%s'", | ||
| zoneEntity.getName()); | ||
| throw new AttributeConnectorException(message, e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Boolean deleteResourceConnector() { | ||
| ZoneEntity zoneEntity = this.zoneResolver.getZoneEntityOrFail(); | ||
| boolean isDeleted = false; | ||
| if (null == zoneEntity.getResourceAttributeConnector()) { | ||
| return isDeleted; | ||
| } | ||
| zoneEntity.setResourceAttributeConnector(null); | ||
| try { | ||
| if (null == zoneEntity.getResourceAttributeConnector()) { | ||
| return isDeleted; | ||
| } | ||
| zoneEntity.setResourceAttributeConnector(null); | ||
| this.zoneRepository.save(zoneEntity); | ||
| isDeleted = true; | ||
| } catch (Exception e) { | ||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| *******************************************************************************/ | ||
| package com.ge.predix.acs.zone.management.dao; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Set; | ||
|
|
||
| import javax.persistence.CascadeType; | ||
|
|
@@ -24,18 +25,20 @@ | |
| import javax.persistence.GeneratedValue; | ||
| import javax.persistence.GenerationType; | ||
| import javax.persistence.Id; | ||
| import javax.persistence.JoinColumn; | ||
| import javax.persistence.OneToMany; | ||
| import javax.persistence.OneToOne; | ||
| import javax.persistence.Table; | ||
| import javax.persistence.UniqueConstraint; | ||
|
|
||
| import org.apache.commons.lang.builder.EqualsBuilder; | ||
| import org.apache.commons.lang.builder.HashCodeBuilder; | ||
|
|
||
| import com.ge.predix.acs.attribute.connector.management.dao.AttributeConnectorEntity; | ||
| import com.fasterxml.jackson.core.JsonParseException; | ||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import com.fasterxml.jackson.databind.JsonMappingException; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.ge.predix.acs.privilege.management.dao.ResourceEntity; | ||
| import com.ge.predix.acs.privilege.management.dao.SubjectEntity; | ||
| import com.ge.predix.acs.rest.AttributeConnector; | ||
| import com.ge.predix.acs.service.policy.admin.dao.PolicySetEntity; | ||
|
|
||
| @Entity | ||
|
|
@@ -45,6 +48,8 @@ | |
| @UniqueConstraint(columnNames = { "subdomain" }) }) | ||
| public class ZoneEntity { | ||
|
|
||
| private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); | ||
|
|
||
| @Id | ||
| @Column(name = "id") | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
|
|
@@ -77,19 +82,11 @@ public class ZoneEntity { | |
| fetch = FetchType.LAZY) | ||
| private Set<PolicySetEntity> policySets; | ||
|
|
||
| @OneToOne( | ||
| optional = true, | ||
| cascade = { CascadeType.ALL }, | ||
| orphanRemoval = true) | ||
| @JoinColumn(name = "resource_attribute_connector", referencedColumnName = "id", nullable = true, updatable = true) | ||
| private AttributeConnectorEntity resourceAttributeConnector; | ||
|
|
||
| @OneToOne( | ||
| optional = true, | ||
| cascade = { CascadeType.ALL }, | ||
| orphanRemoval = true) | ||
| @JoinColumn(name = "subject_attribute_connector", referencedColumnName = "id", nullable = true, updatable = true) | ||
| private AttributeConnectorEntity subjectAttributeConnector; | ||
| @Column(name = "resource_attribute_connector_json", nullable = true) | ||
| private String resourceAttributeConnector; | ||
|
|
||
| @Column(name = "subject_attribute_connector_json", nullable = true) | ||
| private String subjectAttributeConnector; | ||
|
|
||
| public ZoneEntity() { | ||
| } | ||
|
|
@@ -155,19 +152,27 @@ public String toString() { | |
| + ", subdomain=" + this.subdomain + "]"; | ||
| } | ||
|
|
||
| public void setResourceAttributeConnector(final AttributeConnectorEntity connector) { | ||
| this.resourceAttributeConnector = connector; | ||
| public void setResourceAttributeConnector(final AttributeConnector connector) throws JsonProcessingException { | ||
| this.resourceAttributeConnector = OBJECT_MAPPER.writeValueAsString(connector); | ||
| } | ||
|
|
||
| public AttributeConnectorEntity getResourceAttributeConnector() { | ||
| return this.resourceAttributeConnector; | ||
| public AttributeConnector getResourceAttributeConnector() | ||
| throws JsonParseException, JsonMappingException, IOException { | ||
| if (null == this.resourceAttributeConnector) { | ||
| return null; | ||
| } | ||
| return OBJECT_MAPPER.readValue(this.resourceAttributeConnector, AttributeConnector.class); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this method should deserialize the json only when the json has changed
|
||
| } | ||
|
|
||
| public AttributeConnectorEntity getSubjectAttributeConnector() { | ||
| return subjectAttributeConnector; | ||
| public AttributeConnector getSubjectAttributeConnector() | ||
| throws JsonParseException, JsonMappingException, IOException { | ||
| if (null == this.subjectAttributeConnector) { | ||
| return null; | ||
| } | ||
| return OBJECT_MAPPER.readValue(this.subjectAttributeConnector, AttributeConnector.class); | ||
| } | ||
|
|
||
| public void setSubjectAttributeConnector(final AttributeConnectorEntity subjectAttributeConnector) { | ||
| this.subjectAttributeConnector = subjectAttributeConnector; | ||
| public void setSubjectAttributeConnector(final AttributeConnector connector) throws JsonProcessingException { | ||
| this.subjectAttributeConnector = OBJECT_MAPPER.writeValueAsString(connector); | ||
| } | ||
| } | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 29: does not look right to me, if existingConnector is not null then isCreated will be false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this just means that the connector has been updated. If existingConnector is null then isCreated will be true, meaning you are creating a new connector.