Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Copy link
Contributor

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.

Copy link
Author

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.


zoneEntity.setResourceAttributeConnector(connector);
this.zoneRepository.save(zoneEntity);
} catch (Exception e) {
String message = String.format(
Expand All @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add throws clause to this function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guys,
This is good we are using Json thanks for fast turnaround but should we define the fields/format of the Json like:
{
"CLIENTD" : "ddd",
"CLIENDSECRET" : " secret",
"UAAURL" : "uaa_url",
"endpoint" : "ep"
}

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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) {
Expand Down

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
Expand Up @@ -15,6 +15,7 @@
*******************************************************************************/
package com.ge.predix.acs.zone.management.dao;

import java.io.IOException;
import java.util.Set;

import javax.persistence.CascadeType;
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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() {
}
Expand Down Expand Up @@ -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);
Copy link
Contributor

@sanjeevchopra sanjeevchopra Mar 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method should deserialize the json only when the json has changed

  • keep a separate field of type AttributeConnector
  • initialize from json when getter is called, only if null
  • setter should also set this field, and serialize to json only if new value does not equal current value in object

}

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.

Loading