Search in sources :

Example 16 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class MappingServiceController method scheduleMappingJob.

/**
 * Schedules a {@link MappingJobExecution}.
 *
 * @param mappingProjectId   ID of the mapping project
 * @param targetEntityTypeId ID of the target entity to create or update
 * @param label              label of the target entity to create
 * @param packageId          ID of the package to put the newly created entity in
 * @return the href of the created MappingJobExecution
 */
@PostMapping(value = "/map", produces = TEXT_PLAIN_VALUE)
public ResponseEntity<String> scheduleMappingJob(@RequestParam String mappingProjectId, @RequestParam String targetEntityTypeId, @RequestParam(required = false) String label, @RequestParam(required = false, name = "package") String packageId, @RequestParam(required = false) Boolean addSourceAttribute) throws URISyntaxException {
    mappingProjectId = mappingProjectId.trim();
    targetEntityTypeId = targetEntityTypeId.trim();
    label = trim(label);
    packageId = trim(packageId);
    try {
        validateEntityName(targetEntityTypeId);
        if (mappingService.getMappingProject(mappingProjectId) == null) {
            throw new MolgenisDataException("No mapping project found with ID " + mappingProjectId);
        }
        if (packageId != null) {
            Package package_ = dataService.getMeta().getPackage(packageId);
            if (package_ == null) {
                throw new MolgenisDataException("No package found with ID " + packageId);
            }
            if (isSystemPackage(package_)) {
                throw new MolgenisDataException(format("Package [{0}] is a system package.", packageId));
            }
        }
    } catch (MolgenisDataException mde) {
        return ResponseEntity.badRequest().contentType(TEXT_PLAIN).body(mde.getMessage());
    }
    MappingJobExecution mappingJobExecution = scheduleMappingJobInternal(mappingProjectId, targetEntityTypeId, addSourceAttribute, packageId, label);
    String jobHref = concatEntityHref(mappingJobExecution);
    return created(new URI(jobHref)).contentType(TEXT_PLAIN).body(jobHref);
}
Also used : MetaUtils.isSystemPackage(org.molgenis.data.meta.MetaUtils.isSystemPackage) Package(org.molgenis.data.meta.model.Package) URI(java.net.URI) URI(org.molgenis.semanticmapper.controller.MappingServiceController.URI) MappingJobExecution(org.molgenis.semanticmapper.job.MappingJobExecution)

Example 17 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class EntityTypeValidatorTest method testValidateSystemPackageValid.

@Test
public void testValidateSystemPackageValid() {
    String packageName = PACKAGE_SYSTEM;
    Package rootSystemPackage = mock(Package.class);
    when(rootSystemPackage.getId()).thenReturn(packageName);
    String entityTypeId = "entity";
    when(entityType.getId()).thenReturn(entityTypeId);
    when(entityType.getPackage()).thenReturn(rootSystemPackage);
    when(systemEntityTypeRegistry.hasSystemEntityType(entityTypeId)).thenReturn(true);
    // valid
    entityTypeValidator.validate(entityType);
}
Also used : Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 18 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class EntityTypeValidatorTest method testValidateSystemPackageInvalid.

@Test(expectedExceptions = MolgenisValidationException.class, expectedExceptionsMessageRegExp = "Adding entity \\[myEntity\\] to system package \\[sys\\] is not allowed")
public void testValidateSystemPackageInvalid() {
    String packageName = PACKAGE_SYSTEM;
    Package rootSystemPackage = mock(Package.class);
    when(rootSystemPackage.getId()).thenReturn(packageName);
    String entityTypeId = "myEntity";
    when(entityType.getId()).thenReturn(entityTypeId);
    when(entityType.getPackage()).thenReturn(rootSystemPackage);
    when(systemEntityTypeRegistry.hasSystemEntityType(entityTypeId)).thenReturn(false);
    entityTypeValidator.validate(entityType);
}
Also used : Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 19 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class EntityTypeValidatorTest method setUpBeforeMethod.

@SuppressWarnings("unchecked")
@BeforeMethod
public void setUpBeforeMethod() {
    dataService = mock(DataService.class);
    MetaDataService metaDataService = mock(MetaDataService.class);
    when(dataService.getMeta()).thenReturn(metaDataService);
    systemEntityTypeRegistry = mock(SystemEntityTypeRegistry.class);
    entityTypeValidator = new EntityTypeValidator(dataService, systemEntityTypeRegistry);
    String backendName = "backend";
    RepositoryCollection repoCollection = mock(RepositoryCollection.class);
    when(metaDataService.getBackend(backendName)).thenReturn(repoCollection);
    // valid entity meta
    entityType = when(mock(EntityType.class).getId()).thenReturn("entity").getMock();
    idAttr = when(mock(Attribute.class).getName()).thenReturn("idAttr").getMock();
    when(idAttr.getIdentifier()).thenReturn("#idAttr");
    when(idAttr.getDataType()).thenReturn(STRING);
    when(idAttr.isUnique()).thenReturn(true);
    when(idAttr.isNillable()).thenReturn(false);
    labelAttr = when(mock(Attribute.class).getName()).thenReturn("labelAttr").getMock();
    when(labelAttr.getIdentifier()).thenReturn("#labelAttr");
    when(labelAttr.getDataType()).thenReturn(STRING);
    entityQ = mock(Query.class);
    when(dataService.query(ENTITY_TYPE_META_DATA, EntityType.class)).thenReturn(entityQ);
    Query<EntityType> entityQ0 = mock(Query.class);
    Query<EntityType> entityQ1 = mock(Query.class);
    when(entityQ.eq(ATTRIBUTES, idAttr)).thenReturn(entityQ0);
    when(entityQ.eq(ATTRIBUTES, labelAttr)).thenReturn(entityQ1);
    when(entityQ0.findOne()).thenReturn(null);
    when(entityQ1.findOne()).thenReturn(null);
    attrQ = mock(Query.class);
    Query<Attribute> attrQ0 = mock(Query.class);
    Query<Attribute> attrQ1 = mock(Query.class);
    when(dataService.query(ATTRIBUTE_META_DATA, Attribute.class)).thenReturn(attrQ);
    when(attrQ.eq(CHILDREN, idAttr)).thenReturn(attrQ0);
    when(attrQ.eq(CHILDREN, labelAttr)).thenReturn(attrQ1);
    when(attrQ0.findOne()).thenReturn(null);
    when(attrQ1.findOne()).thenReturn(null);
    String packageName = "package";
    Package package_ = when(mock(Package.class).getId()).thenReturn(packageName).getMock();
    when(entityType.getPackage()).thenReturn(package_);
    String name = "name";
    String label = "label";
    when(entityType.getId()).thenReturn(packageName + PACKAGE_SEPARATOR + name);
    when(entityType.getLabel()).thenReturn(label);
    when(entityType.getOwnAllAttributes()).thenReturn(newArrayList(idAttr, labelAttr));
    when(entityType.getAllAttributes()).thenReturn(newArrayList(idAttr, labelAttr));
    when(entityType.getOwnIdAttribute()).thenReturn(idAttr);
    when(entityType.getOwnLabelAttribute()).thenReturn(labelAttr);
    when(entityType.getOwnLookupAttributes()).thenReturn(singletonList(labelAttr));
    when(entityType.isAbstract()).thenReturn(false);
    when(entityType.getExtends()).thenReturn(null);
    when(entityType.getBackend()).thenReturn(backendName);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) SystemEntityTypeRegistry(org.molgenis.data.meta.system.SystemEntityTypeRegistry) RepositoryCollection(org.molgenis.data.RepositoryCollection) MetaDataService(org.molgenis.data.meta.MetaDataService) Query(org.molgenis.data.Query) Attribute(org.molgenis.data.meta.model.Attribute) Package(org.molgenis.data.meta.model.Package) MetaDataService(org.molgenis.data.meta.MetaDataService) DataService(org.molgenis.data.DataService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 20 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class PackageRepositoryValidationDecoratorTest method testDeleteStreamValid.

@Test
public void testDeleteStreamValid() throws Exception {
    Package package_ = mock(Package.class);
    packageRepositoryValidationDecorator.delete(Stream.of(package_));
    @SuppressWarnings("unchecked") ArgumentCaptor<Stream<Package>> packageCaptor = ArgumentCaptor.forClass(Stream.class);
    verify(delegateRepository).delete(packageCaptor.capture());
    assertEquals(packageCaptor.getValue().collect(toList()), singletonList(package_));
    verify(packageValidator).validate(package_);
}
Also used : Stream(java.util.stream.Stream) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Aggregations

Package (org.molgenis.data.meta.model.Package)98 Test (org.testng.annotations.Test)70 EntityType (org.molgenis.data.meta.model.EntityType)22 Stream (java.util.stream.Stream)20 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)13 Attribute (org.molgenis.data.meta.model.Attribute)11 DefaultPackage (org.molgenis.data.meta.DefaultPackage)10 MolgenisValidationException (org.molgenis.data.validation.MolgenisValidationException)10 Objects.requireNonNull (java.util.Objects.requireNonNull)6 L10nString (org.molgenis.data.i18n.model.L10nString)6 PackageIdentity (org.molgenis.data.security.PackageIdentity)6 Collectors.toList (java.util.stream.Collectors.toList)5 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)5 DataService (org.molgenis.data.DataService)5 QueryImpl (org.molgenis.data.support.QueryImpl)5 RepositoryCollection (org.molgenis.data.RepositoryCollection)4 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)3 java.util (java.util)3 Collections.singletonList (java.util.Collections.singletonList)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3