use of org.ligoj.app.model.Project in project ligoj-api by ligoj.
the class TestAbstractConfiguredServicePlugin method prepareMock.
@SuppressWarnings("unchecked")
@BeforeEach
public void prepareMock() {
resource = new AbstractConfiguredServicePlugin<>() {
@Override
public String getKey() {
return "key";
}
@Override
public Object getConfiguration(int subscription) {
return configuration;
}
};
resource.subscriptionRepository = Mockito.mock(SubscriptionRepository.class);
resource.projectRepository = Mockito.mock(ProjectRepository.class);
resource.securityHelper = Mockito.mock(SecurityHelper.class);
repository = Mockito.mock(RestRepository.class);
configuration = Mockito.mock(PluginConfiguration.class);
configurable = Mockito.mock(NamedConfigurable.class);
subscription = new Subscription();
subscription.setId(33);
project = new Project();
project.setId(44);
subscription.setProject(project);
Mockito.when(resource.securityHelper.getLogin()).thenReturn("junit");
Mockito.when(configurable.getConfiguration()).thenReturn(configuration);
Mockito.when(configurable.getId()).thenReturn(1);
Mockito.when(configurable.getName()).thenReturn("my-name");
Mockito.when(configuration.getSubscription()).thenReturn(subscription);
Mockito.when(resource.subscriptionRepository.findOneExpected(33)).thenReturn(subscription);
Mockito.when(resource.projectRepository.findOneVisible(44, "junit")).thenReturn(project);
Mockito.when(repository.findOneExpected(1)).thenReturn(configurable);
Mockito.when(repository.findAllBy("configuration.subscription.id", subscription.getId(), new String[] { "name" }, "my-name")).thenReturn(Collections.singletonList(configurable));
}
use of org.ligoj.app.model.Project in project ligoj-api by ligoj.
the class ToVoConverterTest method applyEmpty.
@Test
public void applyEmpty() {
final ToVoConverter converter = new ToVoConverter(s -> null, new ArrayList<>(), new HashMap<>());
final Project entity = new Project();
entity.setSubscriptions(Collections.emptyList());
final ProjectVo vo = converter.apply(entity);
Assertions.assertNull(vo.getName());
Assertions.assertNull(vo.getPkey());
Assertions.assertNull(vo.getCreatedBy());
Assertions.assertNull(vo.getCreatedDate());
Assertions.assertNull(vo.getLastModifiedBy());
Assertions.assertNull(vo.getLastModifiedDate());
Assertions.assertNull(vo.getTeamLeader());
Assertions.assertNull(vo.getId());
Assertions.assertTrue(vo.getSubscriptions().isEmpty());
}
use of org.ligoj.app.model.Project in project ligoj-api by ligoj.
the class ProjectResource method update.
/**
* Update project. Should be protected with RBAC.
*
* @param vo
* the object to save.
*/
@PUT
public void update(final ProjectEditionVo vo) {
// pkey can't be updated if there is at least subscription.
final Project project = repository.findOneExpected(vo.getId());
final long nbSubscriptions = subscriptionRepository.countByProject(vo.getId());
if (nbSubscriptions == 0) {
project.setPkey(vo.getPkey());
}
DescribedBean.copy(vo, project);
project.setTeamLeader(vo.getTeamLeader());
repository.saveAndFlush(project);
}
use of org.ligoj.app.model.Project in project ligoj-api by ligoj.
the class ProjectResource method delete.
/**
* Delete entity. Should be protected with RBAC.
*
* @param id
* The entity identifier.
*/
@DELETE
@Path("{id:\\d+}")
public void delete(@PathParam("id") final int id) throws Exception {
final Project project = findOneVisible(id, Function.identity());
for (final Subscription subscription : project.getSubscriptions()) {
subscriptionResource.delete(subscription.getId());
}
repository.delete(project);
}
use of org.ligoj.app.model.Project in project ligoj-api by ligoj.
the class SubscriptionResource method create.
/**
* Create subscription.
*
* @param vo
* the subscription.
* @return the created {@link Subscription}.
* @throws Exception
* When the creat fails. Managed at JAX-RS level.
*/
@POST
public int create(final SubscriptionEditionVo vo) throws Exception {
// Validate entities
final Project project = checkVisibleProject(vo.getProject());
checkManagedProject(vo.getProject());
final Node node = checkManagedNodeForSubscription(vo.getNode());
final List<Parameter> acceptedParameters = checkInputParameters(vo);
// Create subscription and parameters that would be removed in case of
// roll-back because of invalid parameters
final Subscription entity = toEntity(vo, project, node);
// Expose the real entity for plug-in since we have loaded it
entity.setProject(project);
// Save this subscription in the transaction
repository.saveAndFlush(entity);
parameterValueResource.create(vo.getParameters(), entity);
// Delegate to the related plug-in the next process
delegateToPlugin(vo, entity);
// Check again the parameters in the final state
checkMandatoryParameters(vo.getParameters(), acceptedParameters, SubscriptionMode.CREATE);
log.info("Subscription of project {} to service {}", vo.getProject(), vo.getNode());
return entity.getId();
}
Aggregations