Skip to content

Commit

Permalink
Bug fix. Fixed regression in the update aspects function UD-287. Also
Browse files Browse the repository at this point in the history
fixed a bug that the update aspect function didn't update the
modification time of the network.
  • Loading branch information
jingjingbic committed May 14, 2019
1 parent b584755 commit 1be66b2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,10 @@ public void clearNetworkSummary(UUID networkId, long fileSize) throws SQLExcepti
* @throws NdexException
* @throws JsonProcessingException
*/
public void saveNetworkEntry(NetworkSummary networkSummary, MetaDataCollection metadata) throws SQLException, NdexException, JsonProcessingException {
public void saveNetworkEntry(NetworkSummary networkSummary, MetaDataCollection metadata, boolean setModificationTime) throws SQLException, NdexException, JsonProcessingException {
String sqlStr = "update network set name = ?, description = ?, version = ?, edgecount=?, nodecount=?, "
+ "properties = ? ::jsonb, cxmetadata = ? :: json, warnings = ?, subnetworkids = ?, "
+ (setModificationTime? "modification_time = localtimestamp, " : "")
+ " is_validated =true where \"UUID\" = ? and is_deleted = false";
try (PreparedStatement pst = db.prepareStatement(sqlStr)) {
pst.setString(1,networkSummary.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ public CXNetworkAspectsUpdater(UUID networkUUID, /*String ownerUserName,*/ Netwo
public void update() throws FileNotFoundException, IOException, DuplicateObjectException, ObjectNotFoundException, NdexException, SQLException {

try ( InputStream inputStream = new FileInputStream(Configuration.getInstance().getNdexRoot() + "/data/" + aspectsCXNetworkID.toString() + "/network.cx") ) {
persistNetworkData(inputStream);
persistNetworkData(inputStream, true);


UUID networkUUID = getNetworkId();
@SuppressWarnings("resource")
NetworkDAO dao = getDAO();
//handle the network properties
NetworkSummary summary = dao.getNetworkSummaryById(networkUUID);
Expand All @@ -65,21 +66,21 @@ public void update() throws FileNotFoundException, IOException, DuplicateObjectE
if ( aspectTable.containsKey(NodesElement.ASPECT_NAME))
summary.setNodeCount((int) aspectTable.get(NodesElement.ASPECT_NAME).getElementCount());

summary.setModificationTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));
//summary.setModificationTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));

if ( aspectTable.containsKey(NetworkAttributesElement.ASPECT_NAME)) {
if ( aspectTable.containsKey(NetworkAttributesElement.ASPECT_NAME)) {
summary.setProperties(properties);
summary.setName(this.networkName);
summary.setDescription(this.description);
summary.setVersion(this.version);
summary.setWarnings(warnings);
}
}
if ( aspectTable.containsKey(SubNetworkElement.ASPECT_NAME)) {
summary.setSubnetworkIds(subNetworkIds);
}
try {
// dao.saveNetworkEntry(summary, (this.provenanceHistory == null? null: provenanceHistory.getEntity()), metadata);
dao.saveNetworkEntry(summary, fullMetaData);
dao.saveNetworkEntry(summary, fullMetaData ,true);
dao.setFlag(getNetworkId(), "has_layout", fullMetaData.getMetaDataElement(CartesianLayoutElement.ASPECT_NAME)!=null);
dao.commit();
} catch (SQLException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ public class CXNetworkLoader implements AutoCloseable {
private Set<String> indexedFields;

// protected String updatedBy;

public CXNetworkLoader(UUID networkUUID, boolean isUpdate, NetworkDAO networkDao, VisibilityType visibility, Set<String> IndexedFields, int sampleGenerationThreshold) {
super();

Expand Down Expand Up @@ -233,7 +232,7 @@ public void persistCXNetwork() throws IOException, DuplicateObjectException, Obj

try ( InputStream inputStream = new FileInputStream(Configuration.getInstance().getNdexRoot() + "/data/" + networkId + "/network.cx") ) {

persistNetworkData(inputStream);
persistNetworkData(inputStream, false);

// logger.info("aspects have been stored.");

Expand All @@ -259,7 +258,7 @@ public void persistCXNetwork() throws IOException, DuplicateObjectException, Obj
summary.setSubnetworkIds(subNetworkIds);
try {
// dao.saveNetworkEntry(summary, (this.provenanceHistory == null? null: provenanceHistory.getEntity()), metadata);
dao.saveNetworkEntry(summary, metadata);
dao.saveNetworkEntry(summary, metadata, false);

dao.commit();
} catch (SQLException e) {
Expand Down Expand Up @@ -435,12 +434,14 @@ public void importNetwork() throws IOException, DuplicateObjectException, Object

/**
* If it is called from a network import function ( db migrator), we don't remove the provenance entry from the metadata.
* @param isAspectUpdate set this flag if updating aspects in network. We are not check if node aspect is missing when
* this parameter is set to true.
* @throws IOException
* @throws DuplicateObjectException
* @throws NdexException
* @throws ObjectNotFoundException
*/
protected void persistNetworkData(InputStream in/*, boolean isImport*/)
protected void persistNetworkData(InputStream in, boolean isAspectUpdate)
throws IOException, DuplicateObjectException, NdexException, ObjectNotFoundException {

CxElementReader2 cxreader = createCXReader(in);
Expand Down Expand Up @@ -529,7 +530,7 @@ protected void persistNetworkData(InputStream in/*, boolean isImport*/)

if(metadata !=null) {

if (metadata.getMetaDataElement(NodesElement.ASPECT_NAME) == null ) {
if ( !isAspectUpdate && metadata.getMetaDataElement(NodesElement.ASPECT_NAME) == null ) {
throw new NdexException ("Nodes aspect is missing.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,8 @@ public void deleteNetwork(final @PathParam("networkid") String id) throws NdexEx
throw new NetworkConcurrentModificationException ();
}
throw new NdexException("Can't delete a read-only network.");
}
}
//TODO: need to check if the network actually exists and give an 404 error for that case.
throw new NdexException("Only network owner can delete a network.");
} catch ( IOException e ) {
throw new NdexException ("Error occurred when deleting network: " + e.getMessage(), e);
Expand Down

0 comments on commit 1be66b2

Please sign in to comment.