Skip to content

Commit

Permalink
Reinstate the erroneously removed identification strategy of hashing …
Browse files Browse the repository at this point in the history
…the serialization
  • Loading branch information
Vogel612 committed Aug 6, 2020
1 parent 368ce77 commit ef0a85c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
Expand Up @@ -75,7 +75,7 @@ protected EntityResourceT getEntityResourceFromDecodedId(String id) {

@Override
public String getId(EntityT entity) {
return IdDeterminationWithHashCode.INSTANCE.getId(entity);
return new IdDeterminationWithHashCode(requestRepository).getId(entity);
}

@Override
Expand Down
Expand Up @@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.winery.repository.rest.resources._support.collections.withoutid;

import org.eclipse.winery.repository.backend.RepositoryFactory;
import org.eclipse.winery.repository.rest.resources._support.IPersistable;
import org.eclipse.winery.repository.rest.resources._support.collections.EntityResource;
import org.eclipse.winery.repository.rest.resources._support.collections.IIdDetermination;
Expand All @@ -29,7 +30,7 @@ public abstract class EntityWithoutIdResource<EntityT> extends EntityResource<En
*/
@SuppressWarnings("unchecked")
public EntityWithoutIdResource(EntityT o, int idx, List<EntityT> list, IPersistable res) {
super((IIdDetermination<EntityT>) IdDeterminationWithHashCode.INSTANCE, o, idx, list, res);
super((IIdDetermination<EntityT>) new IdDeterminationWithHashCode(RepositoryFactory.getRepository()), o, idx, list, res);
}

}
Expand Up @@ -13,26 +13,25 @@
*******************************************************************************/
package org.eclipse.winery.repository.rest.resources._support.collections.withoutid;

import org.eclipse.winery.repository.backend.BackendUtils;
import org.eclipse.winery.repository.backend.IRepository;
import org.eclipse.winery.repository.rest.resources._support.collections.IIdDetermination;

public class IdDeterminationWithHashCode implements IIdDetermination<Object> {

public static final IdDeterminationWithHashCode INSTANCE = new IdDeterminationWithHashCode();
private final IRepository repository;

public IdDeterminationWithHashCode(IRepository repository) {
this.repository = repository;
}

@Override
public String getId(Object entity) {
// We assume that different Object serializations *always* have different hashCodes
// int hash = BackendUtils.getXMLAsString(entity, repository).hashCode();
// assume that an entity knows how to hashCode itself
int hash = entity.hashCode();
// This id generation strategy matches the one employed for searching through a list of entities
// for EntityWithoutIdCollectionResource
// notably this also assumes that the serialization of an entity is deterministic if it does not have an id
int hash = BackendUtils.getXMLAsString(entity, repository).hashCode();
return Integer.toString(hash);
}

/**
* Static wrapper method for functions.tld
*/
public static String getIdStatically(Object entity) {
return IdDeterminationWithHashCode.INSTANCE.getId(entity);
}

}
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.winery.repository.rest.resources.AbstractResourceTest;
import org.junit.jupiter.api.Test;

// TODO these tests rely on the hardcoded hashes of known policies, which may change!
public class PoliciesResourceTest extends AbstractResourceTest {

@Test
Expand All @@ -35,7 +36,9 @@ public void getPoliciesTest() throws Exception {
@Test
public void deletePolicies() throws Exception {
this.setRevisionTo("3cad4e459a8af6082097eab8f978c80b4f5a512e");
this.assertDelete("servicetemplates/http%253A%252F%252Fwinery.opentosca.org%252Ftest%252Fservicetemplates%252Ffruits/baobab_serviceTemplate/boundarydefinitions/policies/1400281569/");
// TODO make this more resilient against changes in the serialization of the working model
// by obtaining the id of the solitary policy with an additional request
this.assertDelete("servicetemplates/http%253A%252F%252Fwinery.opentosca.org%252Ftest%252Fservicetemplates%252Ffruits/baobab_serviceTemplate/boundarydefinitions/policies/1793006451/");
this.assertGet("servicetemplates/http%253A%252F%252Fwinery.opentosca.org%252Ftest%252Fservicetemplates%252Ffruits/baobab_serviceTemplate/boundarydefinitions/policies/", "entitytypes/empty_array.json");
}
}
Expand Up @@ -9,6 +9,6 @@
"name": "grape",
"policyType": "{http://winery.opentosca.org/test/policytypes/fruits}european",
"policyRef": "{http://winery.opentosca.org/test/policytemplates/fruits}italian",
"id": "1400281569"
"id": "1793006451"
}
]

0 comments on commit ef0a85c

Please sign in to comment.